Skip to content
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

Limitation on set-cookie in responseHeaders #744

Open
AlbertSabate opened this issue Feb 4, 2025 · 2 comments
Open

Limitation on set-cookie in responseHeaders #744

AlbertSabate opened this issue Feb 4, 2025 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Winter Of Code 4.0

Comments

@AlbertSabate
Copy link
Collaborator

Describe the bug
There is a limitation when setting cookies header (set-cookie) in the responseHeader.
You cannot set more than one cookie (in an elegant way)

To Reproduce
const responseHeaders = new Header();
responseHeaders.append('set-cookie', 'cookie1...');
responseHeaders.append('set-cookie', 'cookie2...');

return responseHeaders.toJSON();

Only one cookie will be set

Expected behavior
Be able to set multiple cookie in one responseHeader.

@AlbertSabate
Copy link
Collaborator Author

AlbertSabate commented Feb 4, 2025

As a workaround, if you need to set more than 1 cookie in one responseHeader you can do it. Because JS is an awesome technology you can currently do this:

return {
      'set-cookie': cookie[0],
      'Set-Cookie': cookie[1],
      'sEt-Cookie': cookies[2],
    };

This works, but of course is not elegant. We should support the format 'set-cookies': [cookie[0],cookie[1]], which currently is not supported.

@AlbertSabate AlbertSabate added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers bug Something isn't working Winter Of Code 4.0 and removed enhancement New feature or request labels Feb 4, 2025
@aralroca
Copy link
Collaborator

aralroca commented Feb 5, 2025

@AlbertSabate What version of Bun do you have? With Bun 1.2.2:

const h = new Headers();

h.append('set-cookies', 'cookie1');
h.append('set-cookies', 'cookie2');

console.log(h.toJSON())

The log is:

{
  "set-cookies": "cookie1, cookie2",
}

And, if you have an array of cookies, probably you can use .join?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Winter Of Code 4.0
Projects
None yet
Development

No branches or pull requests

2 participants