Open karelklima opened 1 year ago
This seems reasonable. Not sure what we should name the current setCookie
header. setSetCookie
doesn't really roll off the tongue.
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?
How about
setResponseCookie()
for settingSet-Cookie
header andsetRequestCookie()
for settingCookie
asSet-Cookie
is a response header whileCookie
is a request header?
I like that. Perhaps, we could also add getResponseCookie()
and getRequestCookie()
. What do we think?
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 theHeaders
object. There are functions to readCookie
headers and read and assignSet-Cookie
headers, but there is currently no way to setCookie
headers.Describe the solution you'd like
A
setCookie(headers: Headers, cookie: Cookie)
method could set aCookie
header. There is one issue though, a method with this name already exists and it sets theSet-Cookie
header.There is a naming inconsistency in the cookie standard library:
getCookies()
- returns allCookie
headersgetSetCookies()
- returns allSet-Cookie
headerssetCookie(...)
- currently sets aCookie
header, but should set theSet-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 theCookie
parsed object from thegetSetCookies()
method and use that as a value to set cookie in headers directly. It would be possible with thetoString
method, which is private to thecookies.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.