diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-04 18:57:22 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-04 18:57:22 +0100 |
commit | f7e7818e245f14c94ce123746efd427634e56109 (patch) | |
tree | 653eaf13847a56a3ee2776bd8021938fed8f8512 /Lib/test/test_httplib.py | |
parent | d710d147f6a265d6415262d17fed0f61660c3a12 (diff) | |
download | cpython-git-f7e7818e245f14c94ce123746efd427634e56109.tar.gz |
Issue #13713: fix a regression in HTTP chunked reading after 806cfe39f729
(originally issue #13464: Add a readinto() method to http.client.HTTPResponse)
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 425c716051..2a0b3e39da 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -293,15 +293,28 @@ class BasicTest(TestCase): 'Transfer-Encoding: chunked\r\n\r\n' 'a\r\n' 'hello worl\r\n' - '1\r\n' - 'd\r\n' + '3\r\n' + 'd! \r\n' + '8\r\n' + 'and now \r\n' + '22\r\n' + 'for something completely different\r\n' ) + expected = b'hello world! and now for something completely different' sock = FakeSocket(chunked_start + '0\r\n') resp = client.HTTPResponse(sock, method="GET") resp.begin() - self.assertEqual(resp.read(), b'hello world') + self.assertEqual(resp.read(), expected) resp.close() + # Various read sizes + for n in range(1, 12): + sock = FakeSocket(chunked_start + '0\r\n') + resp = client.HTTPResponse(sock, method="GET") + resp.begin() + self.assertEqual(resp.read(n) + resp.read(n) + resp.read(), expected) + resp.close() + for x in ('', 'foo\r\n'): sock = FakeSocket(chunked_start + x) resp = client.HTTPResponse(sock, method="GET") @@ -309,9 +322,10 @@ class BasicTest(TestCase): try: resp.read() except client.IncompleteRead as i: - self.assertEqual(i.partial, b'hello world') - self.assertEqual(repr(i),'IncompleteRead(11 bytes read)') - self.assertEqual(str(i),'IncompleteRead(11 bytes read)') + self.assertEqual(i.partial, expected) + expected_message = 'IncompleteRead(%d bytes read)' % len(expected) + self.assertEqual(repr(i), expected_message) + self.assertEqual(str(i), expected_message) else: self.fail('IncompleteRead expected') finally: @@ -323,29 +337,49 @@ class BasicTest(TestCase): 'Transfer-Encoding: chunked\r\n\r\n' 'a\r\n' 'hello worl\r\n' - '1\r\n' - 'd\r\n' + '3\r\n' + 'd! \r\n' + '8\r\n' + 'and now \r\n' + '22\r\n' + 'for something completely different\r\n' ) + expected = b'hello world! and now for something completely different' + nexpected = len(expected) + b = bytearray(128) + sock = FakeSocket(chunked_start + '0\r\n') resp = client.HTTPResponse(sock, method="GET") resp.begin() - b = bytearray(16) n = resp.readinto(b) - self.assertEqual(b[:11], b'hello world') - self.assertEqual(n, 11) + self.assertEqual(b[:nexpected], expected) + self.assertEqual(n, nexpected) resp.close() + # Various read sizes + for n in range(1, 12): + sock = FakeSocket(chunked_start + '0\r\n') + resp = client.HTTPResponse(sock, method="GET") + resp.begin() + m = memoryview(b) + i = resp.readinto(m[0:n]) + i += resp.readinto(m[i:n + i]) + i += resp.readinto(m[i:]) + self.assertEqual(b[:nexpected], expected) + self.assertEqual(i, nexpected) + resp.close() + for x in ('', 'foo\r\n'): sock = FakeSocket(chunked_start + x) resp = client.HTTPResponse(sock, method="GET") resp.begin() try: - b = bytearray(16) n = resp.readinto(b) except client.IncompleteRead as i: - self.assertEqual(i.partial, b'hello world') - self.assertEqual(repr(i),'IncompleteRead(11 bytes read)') - self.assertEqual(str(i),'IncompleteRead(11 bytes read)') + self.assertEqual(i.partial, expected) + expected_message = 'IncompleteRead(%d bytes read)' % len(expected) + self.assertEqual(repr(i), expected_message) + self.assertEqual(str(i), expected_message) else: self.fail('IncompleteRead expected') finally: |