[Python-checkins] cpython (2.7): Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.

serhiy.storchaka python-checkins at python.org
Tue Dec 17 20:54:14 CET 2013


http://hg.python.org/cpython/rev/ebace0a5a33e
changeset:   88029:ebace0a5a33e
branch:      2.7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue Dec 17 21:49:48 2013 +0200
summary:
  Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin.

files:
  Lib/httplib.py           |  2 +-
  Lib/test/test_httplib.py |  2 ++
  Misc/ACKS                |  1 +
  Misc/NEWS                |  3 +++
  4 files changed, 7 insertions(+), 1 deletions(-)


diff --git a/Lib/httplib.py b/Lib/httplib.py
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -565,7 +565,7 @@
         # 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
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -153,6 +153,8 @@
         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
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -904,6 +904,7 @@
 Rich Salz
 Kevin Samborn
 Ilya Sandler
+Simon Sapin
 Mark Sapiro
 Ty Sarna
 Hugh Sasse
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@
 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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list