diff -r 69ea73015132 Lib/httplib.py --- a/Lib/httplib.py Wed Sep 02 22:07:31 2015 -0400 +++ b/Lib/httplib.py Fri Sep 04 10:08:56 2015 +1200 @@ -810,7 +810,9 @@ method = self._method) (version, code, message) = response._read_status() - if code != 200: + # HTTP/0.9 doesn't support the CONNECT verb, so if httplib has + # concluded HTTP/0.9 is being used something has gone wrong. + if code != 200 or version == "HTTP/0.9": self.close() raise socket.error("Tunnel connection failed: %d %s" % (code, message.strip())) diff -r 69ea73015132 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Wed Sep 02 22:07:31 2015 -0400 +++ b/Lib/test/test_httplib.py Fri Sep 04 10:08:56 2015 +1200 @@ -578,6 +578,15 @@ #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) + self.assertRaises(socket.error, conn._tunnel) + class OfflineTest(TestCase): def test_responses(self): self.assertEqual(httplib.responses[httplib.NOT_FOUND], "Not Found")