mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #485] [MERGED] fix: middleware custom response corrupts binary bodies in dev #607
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#607
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/485
Author: @NathanDrake2406
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/12/2026
Merged by: @james-elicx
Base:
main← Head:fix/middleware-dev-response-parity📝 Commits (1)
48832ebfix: middleware custom response corrupts binary bodies in dev📊 Changes
3 files changed (+46 additions, -1 deletions)
View changed files
📝
packages/vinext/src/index.ts(+1 -1)📝
tests/fixtures/pages-basic/middleware.ts(+24 -0)📝
tests/pages-router.test.ts(+21 -0)📄 Description
Summary
response.text(), which decodes bytes as UTF-8 — this corrupts any binary response (images, protobuf, etc.)response.arrayBuffer()+Buffer.from()correctly (prod-server.ts:961)text()→arrayBuffer()in the dev middleware response path (index.ts:2153)Note: The original audit also flagged multi-value
Set-Cookieloss viaHeaders.forEach()coalescing, but testing confirmed the dev path usesfor...of+appendHeader()which correctly preserves separateSet-Cookieentries per the modern Fetch spec. Added a regression test for that too.Test plan
/binary-responsereturning a 1x1 PNG/multi-cookie-responsereturning 3 Set-Cookie headersmiddleware custom response preserves binary body— verifies PNG magic bytes survive round-tripmiddleware custom response preserves multiple Set-Cookie headers— regression test🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.