Skip to content

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

Merged
pimterry merged 1 commit into
httptoolkit:mainfrom
pcbeingused333:fix/json-falsy-overrides
Nov 24, 2026
Merged

pimterry merged 1 commit into
httptoolkit:mainfrom
pcbeingused333:fix/json-falsy-overrides

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

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

CLAassistant commented Nov 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

@pimterry
pimterry merged commit 5f11e05 into httptoolkit:main Nov 24, 2026
10 checks passed
@pimterry

Copy link
Copy Markdown
Member

Thanks! Merged, I'll release shortly.

By the way, in case you're not aware, HTTP Toolkit Pro is free for all contributors to all https://github.com/httptoolkit repos. If that would be useful, just let me know your email (either here or by sending a message to opensource @ httptoolkit.com) and I'll set you up with an account.

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