mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #173] [MERGED] fix: preserve multiple Set-Cookie headers in middleware forwarding #370
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#370
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/173
Author: @southpolesteve
Created: 2/27/2026
Status: ✅ Merged
Merged: 2/27/2026
Merged by: @southpolesteve
Base:
main← Head:fix/preserve-set-cookie-in-middleware📝 Commits (2)
b814c78fix: preserve multiple Set-Cookie headers in middleware forwarding75a2e30fix: add type annotations for Headers.forEach callback in prod-server📊 Changes
4 files changed (+35 additions, -14 deletions)
View changed files
📝
packages/vinext/src/index.ts(+4 -4)📝
packages/vinext/src/server/app-dev-server.ts(+4 -4)📝
packages/vinext/src/server/middleware.ts(+3 -3)📝
packages/vinext/src/server/prod-server.ts(+24 -3)📄 Description
Summary
Middleware header forwarding used
Headers.set()which overwrites previous values with the same key. When middleware sets multipleSet-Cookieheaders (e.g. session + CSRF + consent cookies), only the last one survived. This brings our behavior in line with how Next.js handles multi-value headers.Changes
middleware.ts--.set()to.append()in both thex-middleware-nextandx-middleware-rewritepathsapp-dev-server.ts--.set()to.append()in both the collection phase (where middleware headers are gathered) and the emission phase (where they are merged into the final response)prod-server.ts-- Array accumulation forSet-Cookiein the middleware header merge path, andgetSetCookie()pattern for custom middleware responses (replacesObject.fromEntries()which collapsed multi-value headers)index.tscodegen --.set()to.append()in the generated App Router production middleware runnerindex.tsPages dev --res.setHeader()tores.appendHeader()for middleware header forwardingAll changes use the same pattern: iterate response headers and use
.append()(orappendHeaderfor Node responses) instead of.set(), which preserves separate entries for headers likeSet-Cookiethat cannot be combined with commas per RFC 6265.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.