]> granicus.if.org Git - python/commitdiff
Merged revisions 86450 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 14 Nov 2010 03:31:52 +0000 (03:31 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 14 Nov 2010 03:31:52 +0000 (03:31 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86450 | senthil.kumaran | 2010-11-13 20:27:49 +0800 (Sat, 13 Nov 2010) | 3 lines

  Fix Issue5111 -  Wrap the Ipv6 host with [] in the Host header
........

Lib/httplib.py
Lib/test/test_httplib.py
Misc/NEWS

index 526509c01ffaacd665873b8a0221df5b004b1d51..e1ace4dfe0670e5635bc4038f564a874376096c0 100644 (file)
@@ -879,6 +879,9 @@ class HTTPConnection:
                         host_enc = self.host.encode("ascii")
                     except UnicodeEncodeError:
                         host_enc = self.host.encode("idna")
+                    # Wrap the IPv6 Host Header with [] (RFC 2732)
+                    if host_enc.find(':') >= 0:
+                        host_enc = "[" + host_enc + "]"
                     if self.port == self.default_port:
                         self.putheader('Host', host_enc)
                     else:
index 74301ff39accb8330ab617104b0ed05237c2cff5..d7b73e131e9711aafb121430bd319084cb066050 100644 (file)
@@ -97,6 +97,26 @@ class HeaderTests(TestCase):
         conn.putheader('Content-length',42)
         self.assertTrue('Content-length: 42' in conn._buffer)
 
+    def test_ipv6host_header(self):
+        # Default host header on IPv6 transaction should wrapped by [] if
+        # its actual IPv6 address
+        expected = 'GET /foo HTTP/1.1\r\nHost: [2001::]:81\r\n' \
+                   'Accept-Encoding: identity\r\n\r\n'
+        conn = httplib.HTTPConnection('[2001::]:81')
+        sock = FakeSocket('')
+        conn.sock = sock
+        conn.request('GET', '/foo')
+        self.assertTrue(sock.data.startswith(expected))
+
+        expected = 'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n' \
+                   'Accept-Encoding: identity\r\n\r\n'
+        conn = httplib.HTTPConnection('[2001:102A::]')
+        sock = FakeSocket('')
+        conn.sock = sock
+        conn.request('GET', '/foo')
+        self.assertTrue(sock.data.startswith(expected))
+
+
 class BasicTest(TestCase):
     def test_status_lines(self):
         # Test HTTP status lines
index f0afdb4ae5c248b633a059b04bb27445c1727ec1..b45fe76793ed31f7049ca9e524910029a421dc8e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #5111: IPv6 Host in the Header is wrapped inside [ ]. Patch by Chandru.
+
 
 What's New in Python 2.7.1 release candidate 1?
 ===============================================