refactor(bedrock): parse request body once in the handler dispatch#315
Merged
vieiralucas merged 1 commit intomainfrom Apr 12, 2026
Merged
refactor(bedrock): parse request body once in the handler dispatch#315vieiralucas merged 1 commit intomainfrom
vieiralucas merged 1 commit intomainfrom
Conversation
``BedrockService::handle`` is a ~600-line match on ``action``. Thirty-four
of its arms started with exactly the same line:
let body: Value = serde_json::from_slice(&req.body).unwrap_or_default();
…before handing the body off to the operation-specific function. Parse
it once at the top of the match and pass the shared ``body`` reference
to each arm instead. Zero behavior change, the dispatcher shrinks by
~54 lines, and the mixed "some arms inline, some arms call a method"
pattern the audit flagged becomes uniform.
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/fakecloud-bedrock/src/service.rs">
<violation number="1" location="crates/fakecloud-bedrock/src/service.rs:754">
P2: JSON is parsed eagerly for every action, which adds unnecessary work and causes double parsing on runtime endpoints that already parse `req.body` downstream.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| action: format!("{} {}", req.method, req.raw_path), | ||
| })?; | ||
|
|
||
| let body = req.json_body(); |
There was a problem hiding this comment.
P2: JSON is parsed eagerly for every action, which adds unnecessary work and causes double parsing on runtime endpoints that already parse req.body downstream.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/fakecloud-bedrock/src/service.rs, line 754:
<comment>JSON is parsed eagerly for every action, which adds unnecessary work and causes double parsing on runtime endpoints that already parse `req.body` downstream.</comment>
<file context>
@@ -751,13 +751,14 @@ impl AwsService for BedrockService {
action: format!("{} {}", req.method, req.raw_path),
})?;
+ let body = req.json_body();
+
match action {
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BedrockService::handleis a ~600-line match onaction. Thirty-four of its arms started with exactly the same line:let body: Value = serde_json::from_slice(&req.body).unwrap_or_default();...before handing the body off to the operation-specific function.
This PR parses the body once at the top of the match and passes the shared
bodyreference to each arm instead. Zero behavior change, the dispatcher shrinks by ~54 lines, and the mixed "some arms inline parsing, some arms call a method" pattern the audit flagged becomes uniform.Test plan
cargo build --workspacecargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace --exclude fakecloud-e2e --exclude fakecloud-conformance— 1102 passed, 0 failedSummary by cubic
Parse the request body once in the Bedrock dispatcher and pass it to all handler arms. Removes duplicated parsing across 34 actions and trims ~54 lines, with no behavior change.
req.json_body()and pass&bodyto handlers.serde_json::from_slice(&req.body).unwrap_or_default()in match arms.Written for commit ceaa90e. Summary will update on new commits.