Skip to content

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

Description

@myselfsiddharth

Bug

res.send() handles Buffer and TypedArray (ArrayBuffer.isView) as binary data, but a raw ArrayBuffer — the standard JavaScript binary data type — falls through to this.json(chunk), producing {}withContent-Type: application/json`.

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

Cause

PR #6285 (merged as 55869f4) fixed Uint8Array/DataView support by adding an ArrayBuffer.isView() check. However, ArrayBuffer.isView(new ArrayBuffer(...)) returns false, so raw ArrayBuffer was missed.

Proposed fix

Add an instanceof ArrayBuffer check in lib/response.js that converts to Buffer and sets the binary content type, consistent with the existing ArrayBuffer.isView branch.

Real-world impact

ArrayBuffer is the standard binary type used by fetch, Web Crypto, WebSocket, FileReader, and similar APIs. Passing it directly to res.send() is a common scenario that currently fails silently.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions