Skip to content

Commit

Permalink
fix: don't clobber set-cookie headers if multiple are present
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Jul 9, 2024
1 parent eea3b61 commit e9f2e71
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,16 +1616,20 @@ export default class NextNodeServer extends BaseServer<
return { finished: true }
}

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

// Clear existing header.
result.response.headers.delete(key)
// Clear existing header(s)
result.response.headers.delete('set-cookie')

// Append each cookie individually.
const cookies = splitCookiesString(value)
for (const cookie of cookies) {
result.response.headers.append(key, cookie)
result.response.headers.append('set-cookie', cookie)
}

// Add cookies to request meta.
Expand Down

0 comments on commit e9f2e71

Please sign in to comment.