-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
fix(docs): add disclaimer about parsing set-cookie #213
base: master
Are you sure you want to change the base?
Conversation
@@ -26,6 +26,8 @@ Parse a HTTP `Cookie` header string and returning an object of all cookie name-v | |||
The `str` argument is the string representing a `Cookie` header value and `options` is an | |||
optional object containing additional parsing options. | |||
|
|||
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`. | |
**Note:** This method does not parse the `Set-Cookie` header. |
It already says it parses the Cookie
header twice in the above paragraph, would prefer to keep the note shorter so someone skimming actually reads it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmao I went in the opposite direction with my suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd split the difference
⚠️ Note: This method does not parse theSet-Cookie
header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am personally in favor of a more detailed description. Honestly I would prefer to talk about the difference and even show a detailed example (on top of what your suggestion is below). The larger we make the block warning for this the more likely someone is to see it IMO. Replying here since this is the one with the discussion, but I lean toward @jonchurch's direction below.
@@ -26,6 +26,8 @@ Parse a HTTP `Cookie` header string and returning an object of all cookie name-v | |||
The `str` argument is the string representing a `Cookie` header value and `options` is an | |||
optional object containing additional parsing options. | |||
|
|||
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example can be improved, as that code works fine.
serialize w/ no options essentially makes a valid Cookie
string as it just sets the cookie name and value.
The real trouble is when folks use the options. Specifically the flag options like HttpOnly, Secure, Partitioned
which aren't key value pairs like a cookie header.
I think we should give folks a little more info so they understand the failure state and risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot do `cookie.parse(cookie.serialize('name', 'value'))`. | |
> ⚠️ **NOTE:** This method does not parse the `set-cookie` header. It parses the `cookie` header. This means you cannot safely parse a `set-cookie` header, or the output of `serialize`. | |
> | |
> E.g. `cookie.parse(cookie.serialize('name', 'value', { httpOnly: true, secure: true, partitioned: true }))` will drop the `httpOnly, secure, partitioned` values entirely. Parsing `set-cookie` header values will result in unexpected results! |
This is a common ask. Maybe this type of disclaimer might help?