]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #22095: Fixed HTTPConnection.set_tunnel with default port. The port
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 28 May 2015 19:37:13 +0000 (22:37 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 28 May 2015 19:37:13 +0000 (22:37 +0300)
value in the host header was set to "None".  Patch by Demian Brecht.

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

index 30fc5251931b33600d38516b3a64d2d765470cee..fc908d214dff25c6aeeb9c2ad23b0d6e84eb0f7e 100644 (file)
@@ -772,8 +772,7 @@ class HTTPConnection:
         if self.sock:
             raise RuntimeError("Can't setup tunnel for established connection.")
 
-        self._tunnel_host = host
-        self._tunnel_port = port
+        self._tunnel_host, self._tunnel_port = self._get_hostport(host, port)
         if headers:
             self._tunnel_headers = headers
         else:
@@ -802,8 +801,8 @@ class HTTPConnection:
         self.debuglevel = level
 
     def _tunnel(self):
-        (host, port) = self._get_hostport(self._tunnel_host, self._tunnel_port)
-        self.send("CONNECT %s:%d HTTP/1.0\r\n" % (host, port))
+        self.send("CONNECT %s:%d HTTP/1.0\r\n" % (self._tunnel_host,
+            self._tunnel_port))
         for header, value in self._tunnel_headers.iteritems():
             self.send("%s: %s\r\n" % (header, value))
         self.send("\r\n")
index dc986a9956e678933bcede0edd30ec6fad5cff42..301458910d6bd82e8027878dccfb7c897944d4ce 100644 (file)
@@ -842,10 +842,12 @@ class TunnelTests(TestCase):
 
         self.assertEqual(conn.sock.host, 'proxy.com')
         self.assertEqual(conn.sock.port, 80)
-        self.assertTrue('CONNECT destination.com' in conn.sock.data)
-        self.assertTrue('Host: destination.com' in conn.sock.data)
+        self.assertIn('CONNECT destination.com', conn.sock.data)
+        # issue22095
+        self.assertNotIn('Host: destination.com:None', conn.sock.data)
+        self.assertIn('Host: destination.com', conn.sock.data)
 
-        self.assertTrue('Host: proxy.com' not in conn.sock.data)
+        self.assertNotIn('Host: proxy.com', conn.sock.data)
 
         conn.close()
 
index 204b84434fd303e107a511c9a3a72b53fab0fb9a..7e36ee6c8bf889fa1c4cbe9dc016bc0d2e009cd6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #22095: Fixed HTTPConnection.set_tunnel with default port.  The port
+  value in the host header was set to "None".  Patch by Demian Brecht.
+
 - Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
   cursor type.