Skip to content

fix: send raw ArrayBuffer as binary instead of JSON - #7453

Closed
dajiaohuang wants to merge 1 commit into
expressjs:masterfrom
dajiaohuang:fix/7362-arraybuffer-binary
Closed

fix: send raw ArrayBuffer as binary instead of JSON#7453
dajiaohuang wants to merge 1 commit into
expressjs:masterfrom
dajiaohuang:fix/7362-arraybuffer-binary

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

Fixes #7362

res.send(ArrayBuffer) was sending {} with Content-Type: application/json because ArrayBuffer.isView() returns false for raw ArrayBuffer, causing it to fall through to this.json().

Problem

ArrayBuffer.isView() only returns true for TypedArray views (like Uint8Array), but raw ArrayBuffer is not a view, so it falls through to this.json(chunk) producing {}.

Solution

Add instanceof ArrayBuffer check to handle raw ArrayBuffer like TypedArray views:

  • Set Content-Type to 'bin' (binary)
  • Convert ArrayBuffer to Buffer before sending

Verification

res.send(new ArrayBuffer(10))
// Before: {} with Content-Type: application/json
// After: 10 zero bytes with Content-Type: application/octet-stream

Fixes expressjs#7362

res.send(ArrayBuffer) was sending {} because ArrayBuffer.isView() returns
false for raw ArrayBuffer, causing it to fall through to this.json().

This adds an instanceof ArrayBuffer check to handle raw ArrayBuffer like
TypedArray views - setting Content-Type to 'bin' and converting to Buffer.
@krzysdz

krzysdz commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7363

@krzysdz krzysdz marked this as a duplicate of #7363 Sep 3, 2026
@krzysdz krzysdz closed this Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

res.send(ArrayBuffer) silently sends {} as JSON

2 participants