classification
Title: httplib: wrong Host header when connecting to IPv6 litteral URL
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: chkneo, dmorr, gdesmott, pitrou (4)
Priority: Keywords patch

Created on 2009-01-30 16:48 by gdesmott, last changed 2009-07-02 17:56 by chkneo.

Files
File name Uploaded Description Edit Remove
5111.diff chkneo, 2009-07-02 09:44 patch file
5311_test.diff chkneo, 2009-07-02 17:56 test_httplib patch
Messages (6)
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: chkneo (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: chkneo (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) 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: chkneo (chkneo) Date: 2009-07-02 17:56
Attaching the test patch
History
Date User Action Args
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