summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2009-12-20 07:10:31 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2009-12-20 07:10:31 (GMT)
commit47fff87027dcf6493d177902b7d851a6582f76d0 (patch)
treea996eb4b11b2d6e8244cf508be144b0f7b89ec3a /Lib/http
parent0639d5aeb61d6b7b0e1e1cbbdd7dd89a420a47f5 (diff)
downloadcpython-47fff87027dcf6493d177902b7d851a6582f76d0.zip
cpython-47fff87027dcf6493d177902b7d851a6582f76d0.tar.gz
cpython-47fff87027dcf6493d177902b7d851a6582f76d0.tar.bz2
Merged revisions 76908 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r76908 | senthil.kumaran | 2009-12-20 11:35:13 +0530 (Sun, 20 Dec 2009) | 4 lines Fix for issue 7291 - urllib2 cannot handle https with proxy requiring auth Refactored HTTPHandler tests and added testcase for proxy authorization. ........
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index fef7185..5581903 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -648,9 +648,18 @@ class HTTPConnection:
if strict is not None:
self.strict = strict
- def set_tunnel(self, host, port=None):
+ def set_tunnel(self, host, port=None, headers=None):
+ """ Sets up the host and the port for the HTTP CONNECT Tunnelling.
+
+ The headers argument should be a mapping of extra HTTP headers
+ to send with the CONNECT request.
+ """
self._tunnel_host = host
self._tunnel_port = port
+ if headers:
+ self._tunnel_headers = headers
+ else:
+ self._tunnel_headers.clear()
def _set_hostport(self, host, port):
if port is None:
@@ -674,12 +683,18 @@ class HTTPConnection:
def _tunnel(self):
self._set_hostport(self._tunnel_host, self._tunnel_port)
- connect_str = "CONNECT %s:%d HTTP/1.0\r\n\r\n" %(self.host, self.port)
+ connect_str = "CONNECT %s:%d HTTP/1.0\r\n" %(self.host, self.port)
connect_bytes = connect_str.encode("ascii")
self.send(connect_bytes)
+ for header, value in self._tunnel_headers.iteritems():
+ header_str = "%s: %s\r\n" % (header, value)
+ header_bytes = header_str.encode("ascii")
+ self.send(header_bytes)
+
response = self.response_class(self.sock, strict = self.strict,
- method= self._method)
+ method = self._method)
(version, code, message) = response._read_status()
+
if code != 200:
self.close()
raise socket.error("Tunnel connection failed: %d %s" % (code,