Skip to content

fix(network): handle_route reads top-level body field as RouteRespons…#1354

Open
uraraneko wants to merge 1 commit into
vercel-labs:mainfrom
uraraneko:fix/network-route-body
Open

fix(network): handle_route reads top-level body field as RouteRespons…#1354
uraraneko wants to merge 1 commit into
vercel-labs:mainfrom
uraraneko:fix/network-route-body

Conversation

@uraraneko
Copy link
Copy Markdown

Fix: network route --body not working — handler reads top-level body as fallback

Closes #1353

Problem

The --body flag on network route has no effect. Intercepted requests are passed through to the real backend instead of being stubbed with
the provided response body.

Root Cause

The CLI parser (cli/src/commands.rs:2516) stores the --body value as a top-level "body" field in the command JSON:

{ "id": "...", "action": "route", "url": "**/api/users", "abort": false, "body": "{\"users\":[]}" }                                           

However, handle_route (cli/src/native/actions.rs:7096-7109) only reads from the nested "response" object to construct a RouteResponse. The
top-level "body" field is never accessed, so RouteEntry.response ends up as None, and resolve_fetch_paused skips Fetch.fulfillRequest —
falling through to Fetch.continueRequest, which lets the request reach the real backend.

Fix

Added an or_else fallback in handle_route that reads the top-level "body" field when "response" is not present, constructing a RouteResponse
with sensible defaults (status 200, content-type application/json):

}).or_else(|| {                                                                                                                               
    cmd.get("body").and_then(|v| v.as_str()).map(|body| {                                                                                     
        RouteResponse {                                                                                                                       
            status: Some(200),                                                                                                                
            body: Some(body.to_string()),                                                                                                     
            content_type: Some("application/json".to_string()),                                                                               
            headers: None,                                                                                                                    
        }                                                                                                                                     
    })                                                                                                                                        
});                                                                                                                                           

This approach:

  • Preserves the existing nested "response" path for full control over status, headers, and content type
  • Does not modify the parser side, keeping the diff minimal
  • Is complementary to the parser-side fix in open PR feat: network mock #381 (which wraps --body into a nested response object)

Verification

  • cargo clippy — no warnings
  • cargo test — all relevant tests pass

…e fallback

When --body is passed via CLI, it is stored as a top-level "body" field
in the command JSON, but handle_route only reads from the nested
"response" object. This adds an or_else fallback that constructs a
RouteResponse (status 200, content-type application/json) from the
top-level "body" field when "response" is absent.

Refs vercel-labs#1353
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 13, 2026

@uraraneko is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: network route --body has no effect — CLI parser and handler field mismatch

1 participant