mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-112064: Fix incorrect handling of negative read sizes in HTTPResponse.read()
(#128270)
The parameter `amt` of `HTTPResponse.read()`, which could be a negative integer, has not been handled before and led to waiting for the connection to close for `keep-alive connections`. Now, this has been fixed, and passing negative values to `HTTPResponse().read()` works the same as passing `None` value.
This commit is contained in:
parent
8e57877e3f
commit
4d0d24f6e3
3 changed files with 24 additions and 1 deletions
|
@ -1092,6 +1092,25 @@ class BasicTest(TestCase):
|
|||
self.assertEqual(resp.read(), expected)
|
||||
resp.close()
|
||||
|
||||
# Explicit full read
|
||||
for n in (-123, -1, None):
|
||||
with self.subTest('full read', n=n):
|
||||
sock = FakeSocket(chunked_start + last_chunk + chunked_end)
|
||||
resp = client.HTTPResponse(sock, method="GET")
|
||||
resp.begin()
|
||||
self.assertTrue(resp.chunked)
|
||||
self.assertEqual(resp.read(n), expected)
|
||||
resp.close()
|
||||
|
||||
# Read first chunk
|
||||
with self.subTest('read1(-1)'):
|
||||
sock = FakeSocket(chunked_start + last_chunk + chunked_end)
|
||||
resp = client.HTTPResponse(sock, method="GET")
|
||||
resp.begin()
|
||||
self.assertTrue(resp.chunked)
|
||||
self.assertEqual(resp.read1(-1), b"hello worl")
|
||||
resp.close()
|
||||
|
||||
# Various read sizes
|
||||
for n in range(1, 12):
|
||||
sock = FakeSocket(chunked_start + last_chunk + chunked_end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue