fix serialization of cookies#2307
Open
karenetheridge wants to merge 1 commit intomojolicious:mainfrom
Open
Conversation
Contributor
karenetheridge
commented
Mar 20, 2026
- only one Cookie header is permitted; all cookies must be in a single string (see https://www.rfc-editor.org/rfc/rfc6265#section-5.4)
- the delimiter between individual cookie-pairs is "; ", not ", " (see https://www.rfc-editor.org/rfc/rfc6265#section-4.2.1)
Grinnz
reviewed
Mar 20, 2026
| my $headers = Mojo::Headers->new; | ||
| $headers->from_hash({Connection => 'close', 'Content-Type' => 'text/html'}); | ||
| is_deeply $headers->to_hash, {Connection => 'close', 'Content-Type' => 'text/html'}, 'right structure'; | ||
| is $headers->to_string, "Connection: close\r\nContent-Type: text/html", 'right string'; |
Contributor
There was a problem hiding this comment.
Is the order of these headers when stringified guaranteed?
Contributor
Author
There was a problem hiding this comment.
The values are stored in an arrayref, so they're output in the same order that they were added. However, from_hash uses a hashref so the order there is not deterministic. I'll fix the test.
Contributor
Author
There was a problem hiding this comment.
Ah, no, I'm wrong, all accesses to the data structure use the names method, which sorts the entries, so the order is consistent.
Member
|
I think there was a reason we don't do this, but i don't quite remember. Cookie headers had to be split up into multiple headers with the same name and not joined as a string or it caused some bugs. 🤔 |
- only one Cookie header is permitted; all cookies must be in a single string (see https://www.rfc-editor.org/rfc/rfc6265#section-5.4) - the delimiter between individual cookie-pairs is "; ", not ", " (see https://www.rfc-editor.org/rfc/rfc6265#section-4.2.1)
eb31b96 to
51f3c06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.