Skip to content

fix(cookie): send dict cookies as a single header - #662

Closed
patrick-immometrica wants to merge 2 commits into
0x676e67:mainfrom
patrick-immometrica:fix/cookie-header
Closed

patrick-immometrica wants to merge 2 commits into
0x676e67:mainfrom
patrick-immometrica:fix/cookie-header

Conversation

@patrick-immometrica

@patrick-immometrica patrick-immometrica commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

fixes how a cookies={...} dict goes out on a request. Before, each dict entry became its own Cookie header line; now src/cookie.rs joins all entries into one header, a=1; b=2, which is the format HTTP/1.1 requires, and an empty dict sends no Cookie header at all. A new test in tests/cookie_test.py sends {"a": "1", "b": "2"} to a local server and checks that exactly one line, cookie: a=1; b=2, arrives.

@0x676e67

0x676e67 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

This doesn’t look quite right. I designed it this way to support multiple Cookie headers in HTTP/2 and HTTP/3. If you want HTTP/1 to send a single header, just combine the cookies into a string like "a=1; b=2". The cookies parameter accepts both str and dict.

@0x676e67 0x676e67 closed this Nov 9, 2026
@patrick-immometrica

patrick-immometrica commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Fair point on HTTP/2 and HTTP/3: RFC 9113 §8.2.3 and RFC 9114 §4.2.1 allow splitting the Cookie header there.

For HTTP/1.1 it's the opposite, RFC 6265 §5.4: "the user agent MUST NOT attach more than one Cookie header field". Right now a dict sends one line per entry over HTTP/1.1, which is what the test shows.

Would you take a version that joins them only when the request goes out as HTTP/1.x, and keeps them split for h2/h3?

@0x676e67

0x676e67 commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Only the internal Jar adjusts Cookie headers based on the negotiated HTTP version. The cookies parameter is specific to wreq-python and isn’t handled by wreq, so the header format needs to be adjusted manually for now.

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.

2 participants