Calling setCookie, deleteCookie multiple times in the same request adds multiple set-cookie headers.
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.5.3
Plugin version
8.1.0
Node.js version
16.14.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
I had tried to clear a cookie set by a different piece of code on the same request. However, it looks like when I call setCookie and deleteCookie in alternates for the same cookie name, there are multiple set-cookie headers in the response.
Steps to Reproduce
Run the following on onSend hook:
reply.setCookie('session', sessionCookie, cookieOptsCopy);
reply.clearCookie('session', cookieOptsCopy);
reply.setCookie('session', sessionCookie, cookieOptsCopy);
reply.clearCookie('session', cookieOptsCopy);
reply.setCookie('session', sessionCookie, cookieOptsCopy);
reply.clearCookie('session', cookieOptsCopy);
reply.setCookie('session', sessionCookie, cookieOptsCopy);
results in something like this:
Expected Behavior
Setting cookie with the same name should modify the existing cookie.
Issue Analytics
- State:
- Created a year ago
- Comments:15 (9 by maintainers)
Top Results From Across the Web
Issues · fastify/fastify-cookie - GitHub
Calling setCookie, deleteCookie multiple times in the same request adds multiple set-cookie headers. bug good first issue ; Add support for encrypting cookies ......
Read more >Multiple Set-cookie headers in HTTP - Stack Overflow
This usually ends up happening when you call session_start() and then session_regenerate_id() on the same page. Each will set its own header. All...
Read more >setcookie - Manual - PHP
One way to set this is by adding the number of seconds before the cookie should expire ... Multiple calls to setcookie() are...
Read more >Cookies, document.cookie - The Modern JavaScript Tutorial
Upon sign in, the server uses the Set-Cookie HTTP-header in the response to set a ... Next time when the request is sent...
Read more >Set-Cookie - HTTP - MDN Web Docs
To send multiple cookies, multiple Set-Cookie headers should be sent ... cookie only for same-site requests, that is, requests originating ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately I will have little time to look into this for a while.
I mean, nested for loops are definitely not the way to go. I would hardly use or even support the pattern described at the top.