Skip to content

Commit b40e5d9

Browse files
lubieowoceKikobeats
authored andcommitted
fix: don't clobber set-cookie headers if multiple are present
1 parent 18adfa2 commit b40e5d9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/next/src/server/next-server.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,16 +1616,20 @@ export default class NextNodeServer extends BaseServer<
16161616
return { finished: true }
16171617
}
16181618

1619-
for (let [key, value] of result.response.headers) {
1620-
if (key.toLowerCase() !== 'set-cookie') continue
1619+
// Split compound (comma-separated) set-cookie headers
1620+
if (result.response.headers.has('set-cookie')) {
1621+
const cookies = result.response.headers
1622+
.getSetCookie()
1623+
.flatMap((maybeCompoundCookie) =>
1624+
splitCookiesString(maybeCompoundCookie)
1625+
)
16211626

1622-
// Clear existing header.
1623-
result.response.headers.delete(key)
1627+
// Clear existing header(s)
1628+
result.response.headers.delete('set-cookie')
16241629

16251630
// Append each cookie individually.
1626-
const cookies = splitCookiesString(value)
16271631
for (const cookie of cookies) {
1628-
result.response.headers.append(key, cookie)
1632+
result.response.headers.append('set-cookie', cookie)
16291633
}
16301634

16311635
// Add cookies to request meta.

0 commit comments

Comments
 (0)