Skip to content

fix(res): support raw ArrayBuffer in res.send() - #7438

Closed
vaibhavmashal wants to merge 1 commit into
expressjs:masterfrom
vaibhavmashal:fix/res-send-arraybuffer
Closed

fix(res): support raw ArrayBuffer in res.send()#7438
vaibhavmashal wants to merge 1 commit into
expressjs:masterfrom
vaibhavmashal:fix/res-send-arraybuffer

Conversation

@vaibhavmashal

Copy link
Copy Markdown

Fixes #7362

Description

Previously, passing a raw \ArrayBuffer\ to
es.send()\ fell through the switch statement in \lib/response.js\ to \ his.json(chunk), resulting in {}\ being sent as JSON response rather than binary data.

Solution

  • Added a check for \chunk instanceof ArrayBuffer\ in
    es.send().
  • Converted raw \ArrayBuffer\ to a \Buffer\ via \Buffer.from(chunk).
  • Set \Content-Type: application/octet-stream\ (using \ his.type('bin')) if \Content-Type\ is not already configured, consistent with \Buffer\ and \ArrayBufferView\ handling.
  • Added unit tests in \ est/res.send.js\ asserting that
    es.send(new ArrayBuffer(10))\ responds with 10 bytes and \Content-Type: application/octet-stream, while respecting custom content types.

Copilot AI lite review requested due to automatic review settings August 31, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@krzysdz

krzysdz commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7363

@krzysdz krzysdz marked this as a duplicate of #7363 Aug 31, 2026
@krzysdz krzysdz closed this Aug 31, 2026
@vaibhavmashal
vaibhavmashal deleted the fix/res-send-arraybuffer branch September 3, 2026 16:54
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

3 participants