Repository navigation
Conversation
The body was only prepared when truthy, so 0 and false skipped the JSON serialization and the content-type header, and fetch sent them as text/plain. Only undefined and null mean "no body" now; an empty string is still left to fetch, as there is nothing to serialize.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
agammann
left a comment
There was a problem hiding this comment.
I traced the new guard through the JSON serialization path: 0 and false now reach isJSONSerializable and get the JSON content type, while undefined, null, and the deliberately excluded empty string keep their existing empty-body behavior. The echo tests check both the bytes sent and the header, so this covers the regression at the public $fetch boundary. I did not run tests locally.
resolves #645
A request body of
0orfalsewas sent astext/plain, while1andtruewere sent as JSON: the body was only prepared when truthy (if (context.options.body && isPayloadMethod(...))), so0andfalseskipped the serialization and thecontent-typeheader and reachedfetch()as they are.The guard now checks for "no body" instead of truthiness: only
undefinedandnullmean no body, as forfetch()itself. An empty string is deliberately left tofetch()as before, since there is nothing to serialize and an emptyapplication/jsonbody would not be a JSON document.isJSONSerializable()already accepted numbers and booleans, so nothing else changes.Tests:
0andfalsearrive asapplication/jsonwith the body0/false;undefinedandnullsend no body and no content type. The first test fails without the fix.Reproduction: https://github.com/rhelling/ofetch-request-body-repo —
0 of 8 casesfail against a build of this branch,2 of 8against 1.5.1 and 2.0.0-alpha.3.Summary by CodeRabbit
0andfalsevalues as JSON bodies.undefinedandnullcontinue to produce empty bodies without a content-type header.