From: Serhiy Storchaka Date: Tue, 17 Dec 2013 19:50:02 +0000 (+0200) Subject: Issue #20007: HTTPResponse.read(0) no more prematurely closes connection. X-Git-Tag: v3.4.0b2~187^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c84ac1f5528d26cb226210c2843b765efae83a4;p=python Issue #20007: HTTPResponse.read(0) no more prematurely closes connection. Original patch by Simon Sapin. --- diff --git a/Lib/http/client.py b/Lib/http/client.py index cc452e2f52..e05c84dab7 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -544,7 +544,7 @@ class HTTPResponse(io.RawIOBase): # connection, and the user is reading more bytes than will be provided # (for example, reading in 1k chunks) n = self.fp.readinto(b) - if not n: + if not n and b: # Ideally, we would raise IncompleteRead if the content-length # wasn't satisfied, but it might break compatibility. self._close_conn() diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index f3c27c2df6..4410a93f4f 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -162,6 +162,9 @@ class BasicTest(TestCase): sock = FakeSocket(body) resp = client.HTTPResponse(sock) resp.begin() + self.assertEqual(resp.read(0), b'') # Issue #20007 + self.assertFalse(resp.isclosed()) + self.assertFalse(resp.closed) self.assertEqual(resp.read(), b"Text") self.assertTrue(resp.isclosed()) self.assertFalse(resp.closed) diff --git a/Misc/ACKS b/Misc/ACKS index 486e2affde..702e67989d 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1086,6 +1086,7 @@ Adrian Sampson James Sanders Ilya Sandler Rafael Santos +Simon Sapin Mark Sapiro Ty Sarna Hugh Sasse diff --git a/Misc/NEWS b/Misc/NEWS index 7c0232d9b8..1b58dea47f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,9 @@ Core and Builtins Library ------- +- Issue #20007: HTTPResponse.read(0) no more prematurely closes connection. + Original patch by Simon Sapin. + - Issue #19912: Fixed numerous bugs in ntpath.splitunc(). - Issue #19911: ntpath.splitdrive() now correctly processes the 'Ä°' character