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

Improved set header and set cookie experience #32

Closed
wesleytodd opened this issue Feb 20, 2020 · 9 comments
Closed

Improved set header and set cookie experience #32

wesleytodd opened this issue Feb 20, 2020 · 9 comments
Labels
discuss Topics for open discussion

Comments

@wesleytodd
Copy link
Member

In a recent thread on the cookie module it became clear that the core setHeader api is not very optimal for some use cases. The main issue is that it does not support progressively adding multiple headers of the same name. The set-cookie header is the most clear example of this because applications often set multiple cookies in one response.

I think there is opportunity to pull some of the behaviors of cookie and cookies into the setHeader method. If we were able to "append header" it would help with the progressive addition of set-cookie headers.

But I wanted to also field the idea of moving a full cookie parsing implementation into node. Is there a clear reason why this is a bad idea? I recognize that small core is a feature, but the ease of a using doing res.setCookie('token', '...') seems to be pretty compelling IMO.

@wesleytodd wesleytodd added web-server-frameworks-agenda discuss Topics for open discussion labels Feb 20, 2020
@wesleytodd wesleytodd changed the title Improved set cookie api Improved set header and set cookie experience Feb 20, 2020
@arei
Copy link

arei commented Feb 20, 2020

I actually think this is a great idea, but let me take a slightly contrary position for a second...

What about the other headers that have encoded information in them that is somewhat hard to parse? I'm particularly thinking of content-type and getting the encoding out of it, but I am sure there are others. Are we signing up to end up creating parsing rules for these as well?

I truly love the idea of adding functionality that makes life easier, but where do we draw the line around that.

@wesleytodd
Copy link
Member Author

I'm particularly thinking of content-type and getting the encoding out of it, but I am sure there are others.

I think each domain will have pros/cons for having a core implementation and to keep the conversations clear I don't want to take on too much at once. We can make individual decisions on what makes sense.

@wesleytodd
Copy link
Member Author

Next steps on this, as discussed on the meeting, are to look at what an improved experience around the entire header handling in http looks like. @mcollina referenced many issues with the current api and how in Fastify the only reasonable way was to not use the setHeader api (links to come). We can discuss what gaps there are and how we can get an api which is better for use by frameworks in general.

@wesleytodd
Copy link
Member Author

Update on next steps: We would like help building a prototype of an improved headers api based on this spec: https://developer.mozilla.org/en-US/docs/Web/API/Headers

The goal will be to have a prototype library frameworks can use in the mean time, to help push the conversation forward with core.

@delvedor
Copy link
Member

@wesleytodd I already have a small prototype, I could make it public and invite you all to collaborate :)

@Ethan-Arrowood
Copy link
Contributor

Would love to collaborate @delvedor

@antsmartian
Copy link

@delvedor It would be great, if you can share the repo here.

@delvedor
Copy link
Member

Here's the repository :)
I just pushed the code, as you can as is still a very small prototype. I started working on it a few weeks ago while reading the spec, which you can find here.

If you want, I can transfer the repo into the Node.js GitHub org :)

https://github.com/delvedor/whatwg-headers

@wesleytodd
Copy link
Member Author

This effort will be wrapped up in #55. Going to close this up for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Topics for open discussion
Projects
None yet
Development

No branches or pull requests

5 participants