summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-01-28 11:54:27 (GMT)
committerGitHub <noreply@github.com>2025-01-28 11:54:27 (GMT)
commite5ab9e37408e2470040407deeb87f618c5f053ee (patch)
treea4211888b1cbdc6855347a0deeed5698e64d0984 /Lib/test
parentea143e67b328d961e3eea9c99ee1131550ce23fc (diff)
downloadcpython-e5ab9e37408e2470040407deeb87f618c5f053ee.zip
cpython-e5ab9e37408e2470040407deeb87f618c5f053ee.tar.gz
cpython-e5ab9e37408e2470040407deeb87f618c5f053ee.tar.bz2
[3.12] gh-112064: Fix incorrect handling of negative read sizes in `HTTPResponse.read()` (GH-128270) (#129396)
gh-112064: Fix incorrect handling of negative read sizes in `HTTPResponse.read()` (GH-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. (cherry picked from commit 4d0d24f6e3dff2864007c3cfd1cf7d49c6ee5317) Co-authored-by: Yury Manushkin <manushkin@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_httplib.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 6e63a88..01f5a10 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1078,6 +1078,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)