summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-12-12 07:30:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-12-12 07:30:18 (GMT)
commitd4a001b23cf66232a48021f39d121ba817b31ef2 (patch)
treef8911bfe50d681b88620dba7bc89d27f0287d0d4
parentd625a1819d01ec4d5817c986fee3068d04aa5280 (diff)
parent4ac7ed97a8cabb5dba6aa25e32cd59d9854dda90 (diff)
downloadcpython-d4a001b23cf66232a48021f39d121ba817b31ef2.zip
cpython-d4a001b23cf66232a48021f39d121ba817b31ef2.tar.gz
cpython-d4a001b23cf66232a48021f39d121ba817b31ef2.tar.bz2
Issue #22095: Fixed HTTPConnection.set_tunnel with default port. The port
value in the host header was set to "None". Patch by Demian Brecht.
-rw-r--r--Lib/http/client.py8
-rw-r--r--Lib/test/test_httplib.py8
-rw-r--r--Misc/NEWS3
3 files changed, 11 insertions, 8 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 4169e60..031d448 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -835,8 +835,7 @@ class HTTPConnection:
if self.sock:
raise RuntimeError("Can't set up 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:
@@ -866,9 +865,8 @@ class HTTPConnection:
self.debuglevel = level
def _tunnel(self):
- (host, port) = self._get_hostport(self._tunnel_host,
- self._tunnel_port)
- connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (host, port)
+ connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (self._tunnel_host,
+ self._tunnel_port)
connect_bytes = connect_str.encode("ascii")
self.send(connect_bytes)
for header, value in self._tunnel_headers.items():
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 90da3fc..a4d0c8f 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1299,11 +1299,13 @@ class TunnelTests(TestCase):
self.assertEqual(conn.sock.host, 'proxy.com')
self.assertEqual(conn.sock.port, 80)
- self.assertTrue(b'CONNECT destination.com' in conn.sock.data)
- self.assertTrue(b'Host: destination.com' in conn.sock.data)
+ self.assertIn(b'CONNECT destination.com', conn.sock.data)
+ # issue22095
+ self.assertNotIn(b'Host: destination.com:None', conn.sock.data)
+ self.assertIn(b'Host: destination.com', conn.sock.data)
# This test should be removed when CONNECT gets the HTTP/1.1 blessing
- self.assertTrue(b'Host: proxy.com' not in conn.sock.data)
+ self.assertNotIn(b'Host: proxy.com', conn.sock.data)
conn.close()
conn.request('PUT', '/', '')
diff --git a/Misc/NEWS b/Misc/NEWS
index fb80c0b..299f432 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -194,6 +194,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 #23016: A warning no longer produces an AttributeError when the program
is run with pythonw.exe.