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

[http/cookie] Add support for adding "Cookie" header #3326

Open
karelklima opened this issue Apr 20, 2023 · 3 comments
Open

[http/cookie] Add support for adding "Cookie" header #3326

karelklima opened this issue Apr 20, 2023 · 3 comments

Comments

@karelklima
Copy link

Is your feature request related to a problem? Please describe.

I am trying to send a fetch request to a server from Deno and memorize cookies set by the server in the response.

The standard library is missing a function to assign a Cookie header to the Headers object. There are functions to read Cookie headers and read and assign Set-Cookie headers, but there is currently no way to set Cookie headers.

Describe the solution you'd like

A setCookie(headers: Headers, cookie: Cookie) method could set a Cookie header. There is one issue though, a method with this name already exists and it sets the Set-Cookie header.

There is a naming inconsistency in the cookie standard library:

  • getCookies() - returns all Cookie headers
  • getSetCookies() - returns all Set-Cookie headers
  • setCookie(...) - currently sets a Cookie header, but should set the Set-Cookie header should the naming of functions be consistent.

Describe alternatives you've considered

I have tried to set the Cookie header directly, but it is not convenient at the moment, as there is no way to easily reuse the Cookie parsed object from the getSetCookies() method and use that as a value to set cookie in headers directly. It would be possible with the toString method, which is private to the cookies.ts module.

I'll be happy to send a PR once it is decided whether to implement this and how to solve the naming issue.

@lino-levan
Copy link
Contributor

This seems reasonable. Not sure what we should name the current setCookie header. setSetCookie doesn't really roll off the tongue.

@babiabeo
Copy link
Contributor

How about setResponseCookie() for setting Set-Cookie header and setRequestCookie() for setting Cookie as Set-Cookie is a response header while Cookie is a request header?

@iuioiua
Copy link
Contributor

iuioiua commented Jan 31, 2024

How about setResponseCookie() for setting Set-Cookie header and setRequestCookie() for setting Cookie as Set-Cookie is a response header while Cookie is a request header?

I like that. Perhaps, we could also add getResponseCookie() and getRequestCookie(). What do we think?

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

No branches or pull requests

4 participants