Skip to content

Conversation

@wesleytodd
Copy link
Member

@wesleytodd wesleytodd commented Nov 19, 2024

This is a common ask. Maybe this type of disclaimer might help?

@wesleytodd wesleytodd changed the title fix(docs): add disclaimer about common report of being unable to pars… fix(docs): add disclaimer about parsing set-cookei Nov 19, 2024
@wesleytodd wesleytodd changed the title fix(docs): add disclaimer about parsing set-cookei fix(docs): add disclaimer about parsing set-cookie Nov 19, 2024
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'))`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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.

Copy link
Member

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.

Copy link
Member

@jonchurch jonchurch Nov 20, 2024

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 the Set-Cookie header.

Copy link
Member Author

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.

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'))`.
Copy link
Member

@jonchurch jonchurch Nov 20, 2024

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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!

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

Successfully merging this pull request may close these issues.

4 participants