]> granicus.if.org Git - python/commitdiff
Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 17 Dec 2013 19:50:02 +0000 (21:50 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 17 Dec 2013 19:50:02 +0000 (21:50 +0200)
Original patch by Simon Sapin.

Lib/http/client.py
Lib/test/test_httplib.py
Misc/ACKS
Misc/NEWS

index cc452e2f52e374ebd6f4e52dc72bb4515e337104..e05c84dab7c658d199cda3d82e0bb6cacaf09a1a 100644 (file)
@@ -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()
index f3c27c2df6aefc1e11d639c651d9fc15e419d1d5..4410a93f4f40192003d7b242b7fd00d43ad3dc48 100644 (file)
@@ -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)
index 486e2affdee654c7aa4f34cadbf70763b159ee41..702e67989d6bbbbae23f9f802c7f4412c1c47db4 100644 (file)
--- 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
index 7c0232d9b8223d61f6df48c1892ef44b68a63a97..1b58dea47f50e6b81f858941253b5facb2f94b9b 100644 (file)
--- 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