summaryrefslogtreecommitdiffstats
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2009-12-20 06:05:13 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2009-12-20 06:05:13 (GMT)
commit7713acf201e9638966a9a8f8e38446400410e826 (patch)
tree27cdca52a87dd6575df9f6c2ab99361f00cea2ea /Lib/httplib.py
parent062d2b52f3128f44bfd853459652e075c9bb5f40 (diff)
downloadcpython-7713acf201e9638966a9a8f8e38446400410e826.zip
cpython-7713acf201e9638966a9a8f8e38446400410e826.tar.gz
cpython-7713acf201e9638966a9a8f8e38446400410e826.tar.bz2
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/httplib.py')
-rw-r--r--Lib/httplib.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 3f44f12..39acd1c 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -667,15 +667,24 @@ class HTTPConnection:
self._method = None
self._tunnel_host = None
self._tunnel_port = None
+ self._tunnel_headers = {}
self._set_hostport(host, port)
if strict is not None:
self.strict = strict
- def set_tunnel(self, host, port=None):
- """ Sets up the host and the port for the HTTP CONNECT Tunnelling."""
+ 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:
@@ -699,7 +708,10 @@ class HTTPConnection:
def _tunnel(self):
self._set_hostport(self._tunnel_host, self._tunnel_port)
- self.send("CONNECT %s:%d HTTP/1.0\r\n\r\n" % (self.host, self.port))
+ self.send("CONNECT %s:%d HTTP/1.0\r\n" % (self.host, self.port))
+ for header, value in self._tunnel_headers.iteritems():
+ self.send("%s: %s\r\n" % (header, value))
+ self.send("\r\n")
response = self.response_class(self.sock, strict = self.strict,
method = self._method)
(version, code, message) = response._read_status()