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.

classification
Title: httplib: wrong Host header when connecting to IPv6 litteral URL
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: chkneo, dmorr, eric.araujo, gdesmott, orsenthil, pitrou, vstinner
Priority: normal Keywords: patch

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:45adminsetgithub: 49361
2010-11-14 03:33:09orsenthilsetstatus: open -> closed

messages: + msg121173
2010-11-13 12:28:45orsenthilsetresolution: fixed
messages: + msg121132
stage: resolved
2010-10-18 17:12:51eric.araujosetnosy: + eric.araujo

versions: - Python 2.6
2010-10-18 17:03:54orsenthilsetassignee: orsenthil

nosy: + orsenthil
2010-10-18 16:58:49vstinnersetnosy: + vstinner
2009-07-02 17:56:33chkneosetfiles: + 5311_test.diff

messages: + msg90028
2009-07-02 14:40:03pitrousetnosy: + pitrou

messages: + msg90016
versions: + Python 2.6, Python 3.1, Python 2.7, Python 3.2, - Python 2.5
2009-07-02 09:44:18chkneosetfiles: + 5111.diff
2009-07-02 09:44:08chkneosetfiles: - 5111.diff
2009-07-02 09:33:28chkneosetmessages: + msg90006
2009-07-02 09:30:08chkneosetfiles: + 5111.diff

nosy: + chkneo
messages: + msg90005

keywords: + patch
type: behavior
2009-03-31 17:40:43dmorrsetnosy: + dmorr
2009-01-30 17:06:43gdesmottsetmessages: + msg80829
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:57gdesmottcreate