diff -r 23a760bdd4b1 Lib/httplib.py --- a/Lib/httplib.py Fri Jan 17 09:29:24 2014 -0600 +++ b/Lib/httplib.py Fri Jan 17 19:08:30 2014 +0000 @@ -1322,9 +1322,9 @@ self._done() return s - def readline(self): + def readline(self, amt=None): if self._line_consumed: - return self._file.readline() + return self._file.readline(amt) assert self._line_left s = self._line[self._line_offset:] self._done() diff -r 23a760bdd4b1 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Fri Jan 17 09:29:24 2014 -0600 +++ b/Lib/test/test_httplib.py Fri Jan 17 19:08:30 2014 +0000 @@ -26,6 +26,9 @@ raise httplib.UnimplementedFileMode() return self.fileclass(self.text) + def close(self): + pass + class EPipeSocket(FakeSocket): def __init__(self, text, pipe_trigger): @@ -413,6 +416,19 @@ self.assertEqual(resp.read(), '') self.assertTrue(resp.isclosed()) + def test_proxy_tunnel_without_status_line(self): + # Issue 17849: Confirm we can read from HTTP/0.9 style responses to + # CONNECT requests. + body = "X-Foo: bar\r\n\r\nhello world" + conn = httplib.HTTPConnection('example.com', strict=False) + conn.sock = FakeSocket(body) + conn.set_tunnel('foo') + try: + conn._tunnel() + except TypeError: + self.fail() + + class OfflineTest(TestCase): def test_responses(self): self.assertEqual(httplib.responses[httplib.NOT_FOUND], "Not Found")