Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MultiDict for headers #3

Closed
shazow opened this issue Oct 9, 2011 · 4 comments
Closed

Use MultiDict for headers #3

shazow opened this issue Oct 9, 2011 · 4 comments
Milestone

Comments

@shazow
Copy link
Member

shazow commented Oct 9, 2011

Currently httplib coerces headers into a dict, which breaks some things. Some monkeypatching might be required.

See also: Issue 15 @ GoogleCode for more discussion.

@piotr-dobrogost
Copy link

Currently httplib coerces headers into a dict, which breaks some things

Well, to be precise the problem is not dict itself but merging headers with the same name into one entry.
It's worth noting it was fixed in Python 3:

2.7.2

>>> import httplib
>>> conn = httplib.HTTPConnection('www.wp.pl')
>>> conn.request('HEAD', '/index.html')
>>> res = conn.getresponse()
>>> print res.getheaders()
[('set-cookie', 'reksticket=1323027255; expires=Tuesday, 06-Dec-11 19:34:15 GMT; path=/; domain=.www.wp.pl,
rekticket=1323027255; expires=Tuesday, 06-Dec-11 19:34:15 GMT; path=/; domain=.wp.pl,
statid=77.255.32.195.20351:1323027255:2355453207:v1; path=/; expires=Wed, 03-Dec-14 19:34:15 GMT,
statid=77.255.32.195.20351:1323027255:2355453207:v1; domain=.wp.pl; path=/; expires=Wed, 03-Dec-14 19:34:15 GMT'),...]

3.2.2

>>> from http import client
>>> conn = client.HTTPConnection('www.wp.pl')
>>> conn.request('HEAD', '/index.html')
>>> res = conn.getresponse()
>>> print(res.getheaders())
[('Set-Cookie', 'reksticket=1323028283; expires=Tuesday, 06-Dec-11 19:51:23 GMT; path=/; domain=.www.wp.pl'), ('Set-Cookie',
'rekticket=1323028283; expires=Tuesday, 06-Dec-11 19:51:23 GMT; path=/; domain=.wp.pl'), ('Set-Cookie',
'statid=77.255.32.195.7252:1323028283:2993994873:v1; path=/; expires=Wed, 03-Dec-14 19:51:23 GMT'), ('Set-Cookie',
'statid=77.255.32.195.7252:1323028283:2993994873:v1; domain=.wp.pl; path=/; expires=Wed, 03-Dec-14 19:51:23 GMT'), ...]

This functionality is provided by (undocumented?) HTTPMessage class and Python issue 4773 HTTPMessage not documented and has inconsistent API across 2.6/3.0 is of interest here. The difference shown above is noted by Joel Verhagen in comment http://bugs.python.org/issue4773#msg154781.

The issue we see was raised as issue 1660009 continuing problem with httplib multiple set-cookie headers Python issue.
John J Lee suggests using getallmatchingheaders() method or headers property of rfc822.Message class to get raw header data.

@shazow
Copy link
Member Author

shazow commented Dec 4, 2011

@piotr-dobrogost Thanks for doing the research and posting an update of the current state. The 3.2.2 thing is very interesting.

Maybe we can punt this issue to "someday when we fork for 3.x" like the rest. :P I'll open a py3 issue to track these things.

@karlcow
Copy link

karlcow commented Jul 27, 2012

Just FYI. It is not totally an issue. It is subtle.

https://github.com/kennethreitz/requests/issues/741#issuecomment-7293231

@shazow
Copy link
Member Author

shazow commented Jul 3, 2014

We have HTTPHeaderDict now, I think it satisfies this.

@shazow shazow closed this as completed Jul 3, 2014
njsmith added a commit to njsmith/urllib3 that referenced this issue Apr 4, 2018
Scaffolding to make a simple trio request work
jalopezsilva added a commit to jalopezsilva/urllib3 that referenced this issue Sep 13, 2020
- Move to staticmethod instead of classmethod, also make it private.
- Error out if SSLTransport isn't available and we need to do
  TLS-in-TLS.
- Avoid modifying the signature of prepare_proxy.
jalopezsilva added a commit to jalopezsilva/urllib3 that referenced this issue Oct 4, 2020
- Add links to HTTP CONNECT.
- Several style improvements.
- Clarified TLS-in-TLS section.
- Updated links on the socks examples.
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

No branches or pull requests

3 participants