Bugs item #831271, was opened at 2003-10-27 19:57 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=831271&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.3 >Status: Closed Resolution: Fixed Priority: 5 Submitted By: Jason R. Coombs (jaraco) Assigned to: Alex Martelli (aleax) Summary: httplib.HTTPConnection._send_request header parsing bug Initial Comment: 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. ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2006-02-20 18:40 Message: Logged In: YES user_id=849994 "Host" shouldn't be None anyway... closing. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2004-12-24 15:53 Message: Logged In: YES user_id=80475 Can this be closed? ---------------------------------------------------------------------- Comment By: Kaj J. Niemi (kajtzu) Date: 2004-02-17 23:06 Message: 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> ---------------------------------------------------------------------- Comment By: Alex Martelli (aleax) Date: 2003-11-02 16:51 Message: 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. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=831271&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com