From: Serhiy Storchaka Date: Tue, 17 Dec 2013 19:49:48 +0000 (+0200) Subject: Issue #20007: HTTPResponse.read(0) no more prematurely closes connection. X-Git-Tag: v2.7.8~188 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c97f5ede8f15ab91b2bc224d6fd7c577b744af63;p=python Issue #20007: HTTPResponse.read(0) no more prematurely closes connection. Original patch by Simon Sapin. --- diff --git a/Lib/httplib.py b/Lib/httplib.py index 5c919d2b2f..56c33413ee 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -565,7 +565,7 @@ class HTTPResponse: # connection, and the user is reading more bytes than will be provided # (for example, reading in 1k chunks) s = self.fp.read(amt) - if not s: + if not s and amt: # Ideally, we would raise IncompleteRead if the content-length # wasn't satisfied, but it might break compatibility. self.close() diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 3e81a2c0f9..f11fac3939 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -153,6 +153,8 @@ class BasicTest(TestCase): sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) resp.begin() + self.assertEqual(resp.read(0), '') # Issue #20007 + self.assertFalse(resp.isclosed()) self.assertEqual(resp.read(), 'Text') self.assertTrue(resp.isclosed()) diff --git a/Misc/ACKS b/Misc/ACKS index 35c9cf0e11..0ec87b3523 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -904,6 +904,7 @@ George Sakkis Rich Salz Kevin Samborn Ilya Sandler +Simon Sapin Mark Sapiro Ty Sarna Hugh Sasse diff --git a/Misc/NEWS b/Misc/NEWS index 5f7485892e..d4a1206d49 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -27,6 +27,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 #19623: Fixed writing to unseekable files in the aifc module.