Issue831271
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2003-10-27 19:57 by jaraco, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (5) | |||
---|---|---|---|
msg18773 - (view) | Author: Jason R. Coombs (jaraco) * | Date: 2003-10-27 19:57 | |
The test on lines 730-731 of httplib.py as released with Python 2.3.2 doesn't do what it's intended to do. Consider >>> headers = { 'hoST': 'www.someplace.org' } >>> 'Host' in ( headers or [k for k in headers.iterkeys() if k.lower() == 'host' ] ) False This sample code demonstrates that the code in httplib at line 730 doesn't work as intended (it should return true for any dict who's keys include 'host' of any case). Clearly the 'or' syntax has confused someone here, because the portion after the or (if executed) is always an empty list. I recommend instead if 'host' in map( str.lower, headers.keys() ): Or a better general solution might be to force all header keys to be case-insensitive strings by overriding str and dict to new case-insensitive versions, something like the attached. This idea, however, is just a suggestion, and probably needs to be thought through more thoroughly. |
|||
msg18774 - (view) | Author: Alex Martelli (aleax) * | Date: 2003-11-02 16:51 | |
Logged In: YES user_id=60314 You're certainly right that lines 730-731 cannot be correct, for exactly the reason you specify; and that forcing case-insensitive header dicts may be a cool idea but it's too invasive for such a simple fix. I've done some timing and I think the simplest and fastest way to check is: if 'host' in [k.lower() for k in headers]: accordingly, I have committed this change to the 2.3 branch in CVS. |
|||
msg18775 - (view) | Author: Kaj J. Niemi (kajtzu) | Date: 2004-02-17 23:06 | |
Logged In: YES user_id=978076 Won't this fail if Host is None? Reason I'm asking is that this changed between python 2.3.2 and 2.3.3 and broke something :) File "/usr/lib/python2.3/httplib.py", line 718, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.3/httplib.py", line 730, in _send_request if 'host' in [k.lower() for k in headers]: AttributeError: 'NoneType' object has no attribute 'lower' <https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=112590> |
|||
msg18776 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2004-12-24 15:53 | |
Logged In: YES user_id=80475 Can this be closed? |
|||
msg18777 - (view) | Author: Georg Brandl (georg.brandl) * | Date: 2006-02-20 18:40 | |
Logged In: YES user_id=849994 "Host" shouldn't be None anyway... closing. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:00 | admin | set | github: 39464 |
2003-10-27 19:57:35 | jaraco | create |