Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add additional x-middleware-set-cookie filtering (#75561)
Previously when we removed this from the response we only did so for
requests that flowed through middleware and static handlers. We should
ensure it's filtered in `sendResponse` as well. The header is only
needed internally.
  • Loading branch information
ztanner committed Feb 10, 2025
commit 15ce69052f1fe2cfb074897ac8743abd2313b8c4
5 changes: 5 additions & 0 deletions packages/next/src/server/send-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export async function sendResponse(

// Copy over the response headers.
response.headers?.forEach((value, name) => {
// `x-middleware-set-cookie` is an internal header not needed for the response
if (name.toLowerCase() === 'x-middleware-set-cookie') {
return
}

// The append handling is special cased for `set-cookie`.
if (name.toLowerCase() === 'set-cookie') {
// TODO: (wyattjoh) replace with native response iteration when we can upgrade undici
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/app-dir/app-middleware/app/cookies/api/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NextResponse } from 'next/server'

export function GET() {
const response = new NextResponse()
response.cookies.set({
name: 'example',
value: 'example',
})

return response
}
Loading