res.send(ArrayBuffer) silently sends {} as JSON
- Dominant language
- JavaScript
- Stars
- 69.5k
- Forks
- 25k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
Description
## 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 {}` with `Content-Type: application/json`.
```js
res.send(new ArrayBuffer(10))
// Sends: {} (Content-Type: application/json)
// Expected: 10 zero bytes (Content-Type: application/octet-stream)
```
## Cause
PR #6285 (merged as 55869f49) 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.
Contributor guide
Research direction
Start in lib/response.js and compare raw ArrayBuffer handling with the existing Buffer and ArrayBuffer.isView paths. Done means res.send(new ArrayBuffer(10)) sends 10 zero bytes with application/octet-stream instead of JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100