Skip to content

feat: add multiple set-cookie headers in middleware #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2023
Merged
Changes from 2 commits
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
9 changes: 4 additions & 5 deletions packages/runtime/src/templates/edge-shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ export const addMiddlewareHeaders = async (
// We need to await the response to get the origin headers, then we can add the ones from middleware.
const res = await originResponse
const response = new Response(res.body, res)
const originCookies = response.headers.get('set-cookie')
middlewareResponse.headers.forEach((value, key) => {
response.headers.set(key, value)
// Append origin cookies after middleware cookies
if (key === 'set-cookie' && originCookies) {
response.headers.append(key, originCookies)
if (key === 'set-cookie') {
response.headers.append(key, value)
} else {
response.headers.set(key, value)
}
})
return response
Expand Down