fix: send raw ArrayBuffer and SharedArrayBuffer as binary - #7419
Closed
haoku123 wants to merge 1 commit into
Closed
Conversation
res.send() handled Buffer and TypedArray views via ArrayBuffer.isView(),
but a bare ArrayBuffer (or SharedArrayBuffer) - the standard binary type
returned by fetch, Web Crypto, WebSocket and FileReader - fell through
to the JSON branch and was silently sent as {} with a JSON content type.
Convert bare ArrayBuffers to Buffer and apply the binary content type,
consistent with the existing isView branch.
Fixes expressjs#7362
This was referenced Aug 14, 2026
Contributor
|
The author of #7363 is not inactive and has given a reaction (rocket emoji) on your comment. Closing as duplicate. |
A rocket for you too ! |
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.
Problem
Closes #7362
res.send()handlesBufferand TypedArray views viaArrayBuffer.isView(), but a bareArrayBuffer— the standard binary type returned byfetch, Web Crypto, WebSocket, FileReader and similar APIs — falls through to the JSON branch:ArrayBuffer.isView(new ArrayBuffer(...))returnsfalse, so the#6285fix that addedUint8Array/DataViewsupport missed bare buffers.Solution
Add an
isArrayBuffer()check inlib/response.jsthat converts toBufferand applies the binary content type, consistent with the existingArrayBuffer.isViewbranch.SharedArrayBufferis covered too:Tests
Four tests in
test/res.send.js:ArrayBufferwith explicit Content-Type sends bytes unchangedArrayBufferwithout Content-Type getsapplication/octet-streamSharedArrayBufferFull suite passes (
npm test→ 1264 passing), lint clean.Note
Re-implements the stalled #7363 (author inactive since July) on current
master, with the same behavior and test coverage.