fix(functions): pass ReadableStream body through without JSON serialization#2469
Open
i-anubhav-anand wants to merge 1 commit into
Open
fix(functions): pass ReadableStream body through without JSON serialization#2469i-anubhav-anand wants to merge 1 commit into
i-anubhav-anand wants to merge 1 commit into
Conversation
kallebysantos
requested changes
Jul 20, 2026
Comment on lines
+295
to
+298
| // a web ReadableStream body requires the half-duplex flag for native (undici) fetch | ||
| ...(typeof ReadableStream !== 'undefined' && body instanceof ReadableStream | ||
| ? { duplex: 'half' } | ||
| : {}), |
Member
There was a problem hiding this comment.
Instead of ternary matching here with the Readable guard again, could you move this into the Readable branch, defined at ln 244.
This can be done by following the same approach that headers does
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 Description
What changed?
FunctionInvokeOptions.bodydocumentsReadableStream<Uint8Array>as a supported type, but the body-inference logic ininvoke()had no branch for it. AReadableStreammatched none of theBlob/ArrayBuffer/string/FormDatacases and fell through toJSON.stringify(functionArgs)— which produces"{}", silently dropping the entire stream payload and mislabeling itapplication/json. This happened in both body-inference paths (with and without a caller-suppliedContent-Type).This PR:
ReadableStreambranch in both paths that forwards the stream untouched (no forcedapplication/json).duplex: 'half'on the fetch call when the body is aReadableStream, which native (undici) fetch requires for a streaming request body — mirroring the existing storage-js behavior added in fix(storage): forward duplex option for stream uploads via uploadToSignedUrl #2287.Why was this change needed?
A documented, supported body type was silently corrupted into
"{}". Per the WHATWG Fetch standard,ReadableStreamis a validBodyInit, and the library's owntypes.tslists it as supported — so serializing it as JSON is a contract violation.🔄 Breaking changes
📋 Checklist
pnpm nx format📝 Additional notes
Fail-before / pass-after — added
test/spec/readablestream-body.spec.ts(Docker-free, custom-fetch capture) covering a stream body both with and without a callerContent-Type, asserting the stream is forwarded unchanged andduplex: 'half'is set:master): ❌ both cases —expect(received).toBe(stream)→Received: "{}"duplex: 'half'set)