summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-12-17 19:51:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-12-17 19:51:40 (GMT)
commitcac05e2e900f804a9a2c42ce9ab27c17b93a0811 (patch)
tree58023e1590e5a7e97bdf520d87a347395b064be8
parent85c24979507c4986573cf3537d048324f71d7854 (diff)
parent1c84ac1f5528d26cb226210c2843b765efae83a4 (diff)
downloadcpython-cac05e2e900f804a9a2c42ce9ab27c17b93a0811.zip
cpython-cac05e2e900f804a9a2c42ce9ab27c17b93a0811.tar.gz
cpython-cac05e2e900f804a9a2c42ce9ab27c17b93a0811.tar.bz2
Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin.
-rw-r--r--Lib/http/client.py2
-rw-r--r--Lib/test/test_httplib.py3
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 8 insertions, 1 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 56f548a..763a903 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -538,7 +538,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()
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 31c0b6a..bcd0a02 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -164,6 +164,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)
diff --git a/Misc/ACKS b/Misc/ACKS
index c002652..ef6853d 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1136,6 +1136,7 @@ Adrian Sampson
James Sanders
Ilya Sandler
Rafael Santos
+Simon Sapin
Mark Sapiro
Ty Sarna
Hugh Sasse
diff --git a/Misc/NEWS b/Misc/NEWS
index e8ab0e7..458e43e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@ Core and Builtins
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