Skip to content

fix: honour falsy json values in beforeRequest/beforeResponse overrides - #234

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

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

Conversation

@pcbeingused333

Copy link
Copy Markdown

buildOverriddenBody chose the json override with if (callbackResult?.json), so a callback returning { json: false }, { json: 0 }, { json: '' } or { json: null } was treated as "no override": the original body was kept and no content-type was set. json is typed as accepting any JSON value (CallbackRequestResult.json, CallbackResponseMessageResult.json), so these are valid.

The check is now !== undefined, matching how body is handled just below and how the callback handler already treats json (result.json !== undefined in request-step-impls.ts). true, objects and the unset case behave as before.

Reproduction

A passthrough rule with beforeResponse: () => ({ json: false }) (or null, 0, '') forwards the upstream body unchanged on main. At the function level, buildOverriddenBody({ json: false }, headers) returns undefined on main and a false body with this change.

Test

New test/passthrough-handling.spec.ts covers false, 0, "", null, true, an object, and no override. 4 fail before the fix, all 7 pass after.


This PR was prepared with AI assistance (Claude Code) and the contributor is responsible for its contents.

buildOverriddenBody ignored json overrides of false, 0, '' and null because
it checked truthiness instead of undefined.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me. Can you sign the CLA please? Then this is ready to merge.

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.

3 participants