can't use multiple HTTP Headers with the same name
See original GitHub issueIn HTTP it allows multiple headers with the same name. However, when I went to test webapp that seems to break when IE10 sends multiple cookie headers, I can’t use httpie to test it as it only puts in the last header value in the request.
example:
$ http -v example.org Cookie:foo1=bar1 User-Agent:BAM\1.0 Cookie:foo2=bar2
Current output:
GET / HTTP/1.1
Accept: _/_
Accept-Encoding: gzip, deflate, compress
Cookie: foo2=bar2
Host: example.org
User-Agent: BAM1.0
//response omitted
Expected output:
GET / HTTP/1.1
Accept: _/_
Accept-Encoding: gzip, deflate, compress
Cookie: foo1=bar1
Cookie: foo2=bar2
Host: example.org
User-Agent: BAM1.0
Really HTTP headers should be represented as a case-insensitive MultiMap of some sort, not a Dict.
Issue Analytics
- State:
- Created 11 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Set more than one HTTP header with the same name?
A recipient MAY combine multiple header fields with the same field name into one field-name: field-value pair, without changing the semantics of ...
Read more >multiple headers of the "same name" allowed in http #3591
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header...
Read more >Setting multiple response headers with same name, different ...
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header...
Read more >Multiple header values with the same name - HTTPie
If the request is sent with multiple headers that are sharing the same name, then the HTTPie will send them individually. It is...
Read more >Multiple Headers With Same Name and different Values - IBM
Datapower is replacing the multiple headers with same header name and different values as single header by concatinating the values.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems like the underlying
urllib3.urlopen()
method (throughhttp.client
) works alright withMultiDict()
, so I’d say that is also an option (we can just set the.headers = <>
) after the creating thePreparedRequest
(possibly not a publicly documented API to mess with, but shouldn’t be a much problem).I’ll create another branch with an implementation of the following suggestion.
Thanks for clarifying the actual behavior, I went with a little bit of an improvisation on this but can modify it to take this into account.
I feel like bytes is the way to go instead of ensuring everything is a string. Since
finalize_headers()
alreadyencode()
everything to bytes, so we can do that during the insertion. But it won’t be needed if we divert toMultiDict
.Sure (the implementation above was just a sketch of what I was planning, not the original patch so I tested the bare minimum. actual implementation will probably include way more comprehensive tests).
Wouldn’t it make sense to bump the version number on the PR that is actually releasing this? But yes, this is a change of behavior (which I guess can be justified since AFAIK the previous behavior was undocumented).
Thanks for your feedback again, will let you when I have the second implementation!
Something so simple yet so unsupported nowadays. Except for httpx. Also I have made something basic to help resolving issues with headers. Check out https://github.com/Ousret/kiss-headers if anyone is looking for a solution.