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

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


http://hg.python.org/cpython/rev/d032245a122c
changeset:   88031:d032245a122c
parent:      88026:d489394a73de
parent:      88030:47ae858cd661
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue Dec 17 21:51:40 2013 +0200
summary:
  Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin.

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


diff --git a/Lib/http/client.py b/Lib/http/client.py
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -538,7 +538,7 @@
         # 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
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -164,6 +164,9 @@
         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
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1136,6 +1136,7 @@
 James Sanders
 Ilya Sandler
 Rafael Santos
+Simon Sapin
 Mark Sapiro
 Ty Sarna
 Hugh Sasse
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@
 Library
 -------
 
+- Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
+  Original patch by Simon Sapin.
+
 - Issue #19946: multiprocessing now uses runpy to initialize __main__ in
   child processes when necessary, allowing it to correctly handle scripts
   without suffixes and submodules that use explicit relative imports or

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


More information about the Python-checkins mailing list