[Python-checkins] cpython (2.7): Issue #17849: Raise sensible exception for invalid HTTP tunnel response

martin.panter python-checkins at python.org
Mon Sep 7 03:20:42 CEST 2015


https://hg.python.org/cpython/rev/3510e5d435db
changeset: 97715:3510e5d435db
branch: 2.7
parent: 97705:d7885be86e0f
user: Martin Panter <vadmium>
date: Mon Sep 07 01:18:47 2015 +0000
summary:
 Issue #17849: Raise sensible exception for invalid HTTP tunnel response
Initial patch from Cory Benfield.
files:
 Lib/httplib.py | 5 +++++
 Lib/test/test_httplib.py | 10 ++++++++++
 Misc/ACKS | 1 +
 Misc/NEWS | 4 ++++
 4 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Lib/httplib.py b/Lib/httplib.py
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -810,6 +810,11 @@
 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,
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -578,6 +578,16 @@
 #self.assertTrue(response[0].closed)
 self.assertTrue(conn.sock.file_closed)
 
+ def test_proxy_tunnel_without_status_line(self):
+ # Issue 17849: If a proxy tunnel is created that does not return
+ # a status code, fail.
+ body = 'hello world'
+ conn = httplib.HTTPConnection('example.com', strict=False)
+ conn.set_tunnel('foo')
+ conn.sock = FakeSocket(body)
+ with self.assertRaisesRegexp(socket.error, "Invalid response"):
+ conn._tunnel()
+
 class OfflineTest(TestCase):
 def test_responses(self):
 self.assertEqual(httplib.responses[httplib.NOT_FOUND], "Not Found")
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -107,6 +107,7 @@
 Thomas Bellman
 Alexander “Саша” Belopolsky
 Eli Bendersky
+Cory Benfield
 David Benjamin
 Oscar Benjamin
 Andrew Bennetts
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,10 @@
 Library
 -------
 
+- Issue #17849: Raise a sensible exception if an invalid response is
+ received for a HTTP tunnel request, as seen with some servers that
+ do not support tunnelling. Initial patch from Cory Benfield.
+
 - Issue #16180: Exit pdb if file has syntax error, instead of trapping user
 in an infinite loop. Patch by Xavier de Gaye.
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /