diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 11:05:38 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 11:05:46 +0900 |
commit | 6cc694c4c77aac634cca05c9943b43f22bbe042a (patch) | |
tree | 09b69821a34ec6804d3e0e912b24b9fe3e81c8aa /Lib/httplib.py | |
parent | cd850db82fbac76771227dd7cf7e2d7b1f39ef96 (diff) | |
download | python-6cc694c4c77aac634cca05c9943b43f22bbe042a.tar.gz python-6cc694c4c77aac634cca05c9943b43f22bbe042a.tar.bz2 python-6cc694c4c77aac634cca05c9943b43f22bbe042a.zip |
Imported Upstream version 2.7.11upstream/2.7.11
Change-Id: I6fd1d4f1828aa56cf9e1ece97699852529157243
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r-- | Lib/httplib.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index 9f1e088..7223ba1 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") @@ -811,6 +810,11 @@ class HTTPConnection: method = self._method) (version, code, message) = response._read_status() + if version == "HTTP/0.9": + # HTTP/0.9 doesn't support the CONNECT verb, so if httplib has + # concluded HTTP/0.9 is being used something has gone wrong. + self.close() + raise socket.error("Invalid response from tunnel request") if code != 200: self.close() raise socket.error("Tunnel connection failed: %d %s" % (code, @@ -1063,7 +1067,7 @@ class HTTPConnection: elif body is not None: try: thelen = str(len(body)) - except TypeError: + except (TypeError, AttributeError): # If this is a file-like object, try to # fstat its file descriptor try: |