Issue 5111: httplib: wrong Host header when connecting to IPv6 litteral URL (original) (raw)

Created on 2009-01-30 16:48 by gdesmott, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
5111.diff chkneo,2009-07-02 09:44 patch file review
5311_test.diff chkneo,2009-07-02 17:56 test_httplib patch review
Messages (8)
msg80827 - (view) Author: Guillaume Desmottes (gdesmott) Date: 2009-01-30 16:48
To reproduce: - Launch a HTTP server listening on an Inet6 socket on, say, port 5555 - Try to connect using the IPv6 loopback: http = httplib.HTTPConnection('[::1]:5555') http.request('GET', '/foo') r = http.getresponse() print r.status - You get 400 (bad-request) instead of 404 It seems that's because the HTTP request is wrong. Python sends this header: Host: ::1:5555 but it should be: Host: [::1]:5555 I'm using python 2.5.2-1ubuntu1 on Intrepid.
msg80829 - (view) Author: Guillaume Desmottes (gdesmott) Date: 2009-01-30 17:06
Actually, this bug is present when you try to connect to any URL containing an IP6 and a port. So, we have the same problem when using, for example: http = httplib.HTTPConnection('[2a01:8790:16d:0:218:de87:164:8745]:5555') but http = httplib.HTTPConnection('[2001:4860:0:1001::68]:80') does work. Probably because we use the default HTTP port.
msg90005 - (view) Author: Chandru (chkneo) Date: 2009-07-02 09:30
As per the RFC 2732 host header should be wrapped with []. I am attaching patch for this too which is applied on trunk(2.7)
msg90006 - (view) Author: Chandru (chkneo) Date: 2009-07-02 09:33
RFC 2732 Section three have the following details. host = hostname | IPv4address IPv6reference ipv6reference = "[" IPv6address "]" The patch contains check for : and adding the brackets
msg90016 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-07-02 14:40
Thanks for the patch. It would be better if you also added a test to Lib/test/test_httplib.py (unless for some reason it's technically impossible to do so).
msg90028 - (view) Author: Chandru (chkneo) Date: 2009-07-02 17:56
Attaching the test patch
msg121132 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-13 12:28
Fixed in r86450 (py3k). Will be back porting shortly.
msg121173 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-14 03:33
r86461 (release31-maint) r86462 (release27-maint)
History
Date User Action Args
2022-04-11 14:56:45 admin set github: 49361
2010-11-14 03:33:09 orsenthil set status: open -> closedmessages: +
2010-11-13 12:28:45 orsenthil set resolution: fixedmessages: + stage: resolved
2010-10-18 17:12:51 eric.araujo set nosy: + eric.araujoversions: - Python 2.6
2010-10-18 17:03:54 orsenthil set assignee: orsenthilnosy: + orsenthil
2010-10-18 16:58:49 vstinner set nosy: + vstinner
2009-07-02 17:56:33 chkneo set files: + 5311_test.diffmessages: +
2009-07-02 14:40:03 pitrou set nosy: + pitroumessages: + versions: + Python 2.6, Python 3.1, Python 2.7, Python 3.2, - Python 2.5
2009-07-02 09:44:18 chkneo set files: + 5111.diff
2009-07-02 09:44:08 chkneo set files: - 5111.diff
2009-07-02 09:33:28 chkneo set messages: +
2009-07-02 09:30:08 chkneo set files: + 5111.diffnosy: + chkneomessages: + keywords: + patchtype: behavior
2009-03-31 17:40:43 dmorr set nosy: + dmorr
2009-01-30 17:06:43 gdesmott set messages: + title: httplib: wrong Host header when connecting to IPv6 loopback -> httplib: wrong Host header when connecting to IPv6 litteral URL
2009-01-30 16:48:57 gdesmott create