[issue34516] httplib sets unbefitting "Host" in request header when requests an ipv6 format url.
New submission from chen wu : when I tried to request a url like "https://[fc00:0a08::2]:35357", I got 400. The code is like: import requests requests.get("https://[fc00:0a08::2]:35357";, verify=False) And the apache logs: vhost.c(889): [client fc00:ac1c::9a5:58692] AH00550: Client sent malformed Host header: [[fc00::0a08::2]]:35357 If user no set "Host" in header, httpslib will pase it from url and set it. The paser function is urllib3.util.url.pase_url. When url is "https://[fc00:0a08::2]:35357";, we got host [fc00:0a08::2]. And then httplib sets host in putrequest, "[" and "]" will be added to [fc00:0a08::2], which is not a valid format for host. The part of codes are: 974# Wrap the IPv6 Host Header with [] (RFC 2732) 975if host_enc.find(':') >= 0: 976host_enc = "[" + host_enc + "]" maybe the judgement condition for wrap ipv6 host header with [] is not very well? -- components: Library (Lib) messages: 324149 nosy: visionwun priority: normal severity: normal status: open title: httplib sets unbefitting "Host" in request header when requests an ipv6 format url. type: behavior versions: Python 2.7 ___ Python tracker <https://bugs.python.org/issue34516> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34516] httplib sets unbefitting "Host" in request header when requests an ipv6 format url.
chen wu added the comment: Thanks so much for your reply. when httplib.HTTPConnection is inited with host [fc00::0a08::2] and port 35357, we can make a request normally. only the 'Host' set in header is wrong. I think the most simple way to fix this is adding judgement condition, maybe like this: 974# Wrap the IPv6 Host Header with [] (RFC 2732) 975if host_enc.find(':') >= 0 and host_enc.find(']') < 0: 976host_enc = "[" + host_enc + "]" or rules should be given, because when port is not default, only (host=[aaa:bbb]:123, port=None) and (host=aaa:bbb, port=123) are valid for httplib now. so sorry for my poor English. hope you can understand what im saying. :) -- ___ Python tracker <https://bugs.python.org/issue34516> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34516] httplib sets unbefitting "Host" in request header when requests an ipv6 format url.
chen wu added the comment: yeah, i noticed that. but this function also return host with '[]'. 183# IPv6 184if url and url[0] == '[': 185host, url = url.split(']', 1) 186host += ']' if url is [aaa:bbb]:123, host is [aaa:bbb] and url is ':123'after this process. when host=[aaa:bbb] passed to httplib.HTTPConnection, its function 'putrequest' will put 'Host:[[aaa:bbb]]:123' in headers. -- ___ Python tracker <https://bugs.python.org/issue34516> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34516] httplib sets unbefitting "Host" in request header when requests an ipv6 format url.
chen wu added the comment: to fix this, we change the code of our urilib3. before passing params to httplib, we set Host in headers if it's ipv6 address. Thanks so much. -- resolution: duplicate -> not a bug stage: -> resolved status: pending -> closed ___ Python tracker <https://bugs.python.org/issue34516> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com