-
Notifications
You must be signed in to change notification settings - Fork 86
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
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick debugging on this, @sarahetter! 🎉
(but added the comment on the code as I've just thought about it!)
Summary
Fixes an issue where Deno Headers.set overwrites the previously set header, instead of adding a new
set-cookie
header. This means that we only ever had oneset-cookie
header, which was always the most recently added cookie.You are supposed to set multiple
set-cookie
headers, one per cookie (not a string of multiple cookies in one header). Deno's PR to add the ability to add multipleset-cookie
headers uses theappend
method. See example in their test files for the PR.I removed @taty2010 's work to do with adding originCookies , as it turned out not to be required - the origin set-cookie headers were already present in the
response
object, but because we were doingresponse.headers.set(key, value)
with a middlewareset-cookie
header, it removed all of the origin set-cookie headers and replaced them with the last-executed middlewareset-cookie
header. This PR is tested by the original tests in Taty's original PR.This PR also solves an issue where you were only able to set one cookie in your middleware file, which we thought was a feature but was actually a bug 🐛 😅
Test plan
response.cookies.set('something', 'myvalue)
to a middleware.ts fileset-cookie
headers (multiple from middleware, one from origin) are present on the response.Related: https://github.com/netlify/pillar-support/issues/306
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.