Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7c199f

Browse files
committed
#10983: fix several bugs in the _tunnel implementation that seem to have missed while porting between branches. A unittest is needed!
1 parent 5953128 commit c7c199f

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/http/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ def __init__(self, host, port=None, strict=_strict_sentinel,
653653
self._method = None
654654
self._tunnel_host = None
655655
self._tunnel_port = None
656+
self._tunnel_headers = {}
656657

657658
self._set_hostport(host, port)
658659

@@ -691,15 +692,16 @@ def set_debuglevel(self, level):
691692

692693
def _tunnel(self):
693694
self._set_hostport(self._tunnel_host, self._tunnel_port)
694-
connect_str = "CONNECT %s:%d HTTP/1.0\r\n" %(self.host, self.port)
695+
connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (self.host, self.port)
695696
connect_bytes = connect_str.encode("ascii")
696697
self.send(connect_bytes)
697-
for header, value in self._tunnel_headers.iteritems():
698+
for header, value in self._tunnel_headers.items():
698699
header_str = "%s: %s\r\n" % (header, value)
699700
header_bytes = header_str.encode("latin1")
700701
self.send(header_bytes)
702+
self.send(b'\r\n')
701703

702-
response = self.response_class(self.sock, method = self._method)
704+
response = self.response_class(self.sock, method=self._method)
703705
(version, code, message) = response._read_status()
704706

705707
if code != 200:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Core and Builtins
1616
Library
1717
-------
1818

19+
- Issue #10983: Fix several bugs making tunnel requests in http.client.
20+
1921
- Issue #10955: zipimport uses ASCII encoding instead of cp497 to decode
2022
filenames, at bootstrap, if the codec registry is not ready yet. It is still
2123
possible to have non-ASCII filenames using the Unicode flag (UTF-8 encoding)

0 commit comments

Comments
 (0)