Skip to content

fix(res.send): preserve bytes when sending DataView - #7433

Open
bun-unsafe wants to merge 1 commit into
expressjs:masterfrom
bun-unsafe:fix/res-send-dataview
Open

fix(res.send): preserve bytes when sending DataView#7433
bun-unsafe wants to merge 1 commit into
expressjs:masterfrom
bun-unsafe:fix/res-send-dataview

Conversation

@bun-unsafe

Copy link
Copy Markdown

res.send(new DataView(buffer)) returned HTTP 200 with Content-Length: 0 and an empty body. res.send(new Uint8Array(buffer)) on the same bytes sent the payload.

ArrayBuffer.isView is true for DataView, so the value is treated as binary. The length path then uses chunk.length / Buffer.from(chunk, encoding). DataView has no .length (only .byteLength), and Buffer.from(dataView) is an empty Buffer.

This copies non-Buffer views with Buffer.from(view.buffer, view.byteOffset, view.byteLength). Existing Buffer and Uint8Array behavior is unchanged.

This does not change bare ArrayBuffer (still sent as {} JSON). That is covered by #7362.

Tests: test/res.send.js for a full DataView and a sliced DataView.

DataView is an ArrayBuffer view but has no .length, so the binary
path produced an empty body with HTTP 200. Copy via byteOffset/byteLength.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant