From: Serhiy Storchaka Date: Thu, 28 May 2015 19:37:13 +0000 (+0300) Subject: Issue #22095: Fixed HTTPConnection.set_tunnel with default port. The port X-Git-Tag: v2.7.11rc1~290 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d1de8a2a983e6baa39dbc8587b1730e8ce89956;p=thirdparty%2FPython%2Fcpython.git Issue #22095: Fixed HTTPConnection.set_tunnel with default port. The port value in the host header was set to "None". Patch by Demian Brecht. --- diff --git a/Lib/httplib.py b/Lib/httplib.py index 30fc5251931b..fc908d214dff 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -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") diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index dc986a9956e6..301458910d6b 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -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() diff --git a/Misc/NEWS b/Misc/NEWS index 204b84434fd3..7e36ee6c8bf8 100644 --- 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.