Skip to content

fix: honour falsy json overrides when beforeRequest returns the original body - #236

Open
pcbeingused333 wants to merge 1 commit into
httptoolkit:mainfrom
pcbeingused333:fix/falsy-json-request-override
Open

pcbeingused333 wants to merge 1 commit into
httptoolkit:mainfrom
pcbeingused333:fix/falsy-json-request-override

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

If a beforeRequest callback returns the original body together with a falsy json value, e.g. { ...req, body: req.body.buffer, json: false } (or plain { ...req, json: 0 } from JS), the json override is dropped and the original body is sent upstream.

The cause is that returnsOriginalBody checks if (result?.json), so false, 0, '' and null fall through to the "same body as the input" check, which then skips buildOverriddenBody. It now checks !== undefined, matching buildOverriddenBody after #234.

The new test in http-proxying.spec.ts covers all four values. It fails on main ('original body' instead of 'false') and passes with this change; the rest of that spec file passes too.


This PR was prepared with AI assistance (Claude Code).

This branch has not been deployed

No deployments
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.

1 participant