]> 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:49:48 +0000 (21:49 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 17 Dec 2013 19:49:48 +0000 (21:49 +0200)
Original patch by Simon Sapin.

Lib/httplib.py
Lib/test/test_httplib.py
Misc/ACKS
Misc/NEWS

index 5c919d2b2fafb81b98b1b26a43e91538fda4ebc9..56c33413ee0780c0017802a8b324b3196dd0ca94 100644 (file)
@@ -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()
index 3e81a2c0f9aa846eecbc600b6be370186f5860a0..f11fac393930a18ffe8ecc6690bda2a31dca3c0f 100644 (file)
@@ -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())
 
index 35c9cf0e1177eca5621d84182efe211334a5cb2f..0ec87b3523b67837ccfa2fb64d469d1e79efc52c 100644 (file)
--- 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
index 5f7485892ea369ffd2f36a057ae74d2f4052118a..d4a1206d490c99ea9e89073c42b170488531acea 100644 (file)
--- 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.