-
Notifications
You must be signed in to change notification settings - Fork 84
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
Set-Cookie headers are merged when using fetch
#536
Comments
Hi, from the looks of it, I believe that this works as-per spec: Here,
|
The spec also says that
So you might need to do the for-each loop as in https://github.com/edenstrom/vercel-set-cookie-header/blob/c91a21a0e90c282b2144b84f7524902a2c9ea853/src/app/api/parseEdge/route.ts#L21 instead of https://github.com/edenstrom/vercel-set-cookie-header/blob/c91a21a0e90c282b2144b84f7524902a2c9ea853/src/app/api/edge/route.ts#L18 Combining this info, I think the correct way to write this would be: import { NextRequest, NextResponse } from "next/server"
export const runtime = "edge"
export const GET = async (req: NextRequest) => {
const url = `${req.nextUrl.origin}/api/cookie`
const sessionResponse = await fetch(url, { credentials: "include" })
const setCookies = sessionResponse.headers.getSetCookie() ?? []
const response = NextResponse.json({
route: "success. Returns multiple Set-Cookie headers"
})
for (const cookie in setCookies) {
response.cookies.set("set-cookie", cookie)
}
return response
} |
Related microsoft/TypeScript#55270 |
Hey! Yeah, you're right that it's according to spec. Just a weird use-case when it's server-to-server. 😅 Sadly there's no support for Related: The code in the edge-compatible |
Correct, this is now confirmed not to be a bug in
I'm closing this issue then. Thanks! |
@balazsorban44 Is there anywhere that interested parties can follow along with the progress of the bug fix (a public issue, or a commitment that an update will be shared somewhere)? |
Bug Report
Current behavior
Forwarding
Set-Cookie
headers fromfetch
concatenates multiple ones into a single comma-separatedSet-Cookie
header. This happens only when deployed as en edge route.The main issue is that if the Set-Cookie header exceeds 4096 bytes, everything after gets discarded by the browser. (Related issue: nextauthjs/next-auth#7443 (comment))
Expected behavior/code
The Set-Cookie headers should be preserved as-is and not concatenated.
Additional context/screenshots
Reproduction: https://vercel-set-cookie-header.vercel.app/
Repo: https://github.com/edenstrom/vercel-set-cookie-header
Example contains four routes.
Test using the buttons. Check the cookie panel in devtools. Notice that only the
giant
cookie updates with/api/edge
./api/cookie
/api/node
/api/edge
/api/parseEdge
@edge-runtime/cookies
and forwards headersThe text was updated successfully, but these errors were encountered: