Skip to content

Commit b51263a

Browse files
committed
remove unnecessary internal middleware header from response
1 parent 87c2c52 commit b51263a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/next/src/server/lib/router-utils/resolve-routes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,14 @@ export function getResolveRoutes(
585585
) {
586586
continue
587587
}
588+
589+
// for set-cookie, the header shouldn't be added to the response
590+
// as it's only needed for the request to the middleware function.
591+
if (key === 'x-middleware-set-cookie') {
592+
req.headers[key] = value
593+
continue
594+
}
595+
588596
if (value) {
589597
resHeaders[key] = value
590598
req.headers[key] = value

test/e2e/app-dir/app-middleware/app-middleware.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { nextTestSetup, FileRef } from 'e2e-utils'
66
import type { Response } from 'node-fetch'
77

88
describe('app-dir with middleware', () => {
9-
const { next } = nextTestSetup({
9+
const { next, isNextDeploy } = nextTestSetup({
1010
files: __dirname,
1111
})
1212

@@ -187,6 +187,15 @@ describe('app-dir with middleware', () => {
187187
await browser.deleteCookies()
188188
})
189189

190+
// TODO: Re-enable this test in deploy mode once Vercel has proper handling
191+
if (!isNextDeploy) {
192+
it('should omit internal headers for middleware cookies', async () => {
193+
const response = await next.fetch('/rsc-cookies/cookie-options')
194+
expect(response.status).toBe(200)
195+
expect(response.headers.get('x-middleware-set-cookie')).toBeNull()
196+
})
197+
}
198+
190199
it('should be possible to read cookies that are set during the middleware handling of a server action', async () => {
191200
const browser = await next.browser('/rsc-cookies')
192201
const initialRandom1 = await browser.elementById('rsc-cookie-1').text()

0 commit comments

Comments
 (0)