Skip to content

fix serialization of cookies#2307

Open
karenetheridge wants to merge 1 commit intomojolicious:mainfrom
karenetheridge:ether/fix-cookie-serialization
Open

fix serialization of cookies#2307
karenetheridge wants to merge 1 commit intomojolicious:mainfrom
karenetheridge:ether/fix-cookie-serialization

Conversation

@karenetheridge
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the order of these headers when stringified guaranteed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, no, I'm wrong, all accesses to the data structure use the names method, which sorts the entries, so the order is consistent.

@kraih
Copy link
Member

kraih commented Mar 21, 2026

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)
@karenetheridge karenetheridge force-pushed the ether/fix-cookie-serialization branch from eb31b96 to 51f3c06 Compare March 21, 2026 05:10
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.

3 participants