Code Monkey home page Code Monkey logo

Comments (4)

piotr-dobrogost avatar piotr-dobrogost commented on August 24, 2024

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.

from urllib3.

shazow avatar shazow commented on August 24, 2024

@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.

from urllib3.

karlcow avatar karlcow commented on August 24, 2024

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

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

from urllib3.

shazow avatar shazow commented on August 24, 2024

We have HTTPHeaderDict now, I think it satisfies this.

from urllib3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.