Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cac05e2

Browse files
Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin.
2 parents 85c2497 + 1c84ac1 commit cac05e2

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def readinto(self, b):
538538
# connection, and the user is reading more bytes than will be provided
539539
# (for example, reading in 1k chunks)
540540
n = self.fp.readinto(b)
541-
if not n:
541+
if not n and b:
542542
# Ideally, we would raise IncompleteRead if the content-length
543543
# wasn't satisfied, but it might break compatibility.
544544
self._close_conn()

Lib/test/test_httplib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def test_status_lines(self):
164164
sock = FakeSocket(body)
165165
resp = client.HTTPResponse(sock)
166166
resp.begin()
167+
self.assertEqual(resp.read(0), b'') # Issue #20007
168+
self.assertFalse(resp.isclosed())
169+
self.assertFalse(resp.closed)
167170
self.assertEqual(resp.read(), b"Text")
168171
self.assertTrue(resp.isclosed())
169172
self.assertFalse(resp.closed)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ Adrian Sampson
11361136
James Sanders
11371137
Ilya Sandler
11381138
Rafael Santos
1139+
Simon Sapin
11391140
Mark Sapiro
11401141
Ty Sarna
11411142
Hugh Sasse

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
48+
Original patch by Simon Sapin.
49+
4750
- Issue #19946: multiprocessing now uses runpy to initialize __main__ in
4851
child processes when necessary, allowing it to correctly handle scripts
4952
without suffixes and submodules that use explicit relative imports or

0 commit comments

Comments
 (0)