diff options
author | Georg Brandl <georg@python.org> | 2008-02-24 00:03:22 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-02-24 00:03:22 +0000 |
commit | 2363503074a3f1c2dbe934bed0c865d326e34c1a (patch) | |
tree | 5d9a22409e0fb92e604f0758a0d7a1425ce9363c /Lib/test | |
parent | 5e8e6d2454258d76611444a7260f05094f66d205 (diff) | |
download | cpython-git-2363503074a3f1c2dbe934bed0c865d326e34c1a.tar.gz |
#900744: If an invalid chunked-encoding header is sent by a server,
httplib will now raise IncompleteRead and close the connection instead
of raising ValueError.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_httplib.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index d312ae5fa9..e9dd9d66c3 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -156,6 +156,35 @@ class BasicTest(TestCase): conn.request('GET', '/foo', body) self.assertTrue(sock.data.startswith(expected)) + def test_chunked(self): + chunked_start = ( + 'HTTP/1.1 200 OK\r\n' + 'Transfer-Encoding: chunked\r\n\r\n' + 'a\r\n' + 'hello worl\r\n' + '1\r\n' + 'd\r\n' + ) + sock = FakeSocket(chunked_start + '0\r\n') + resp = httplib.HTTPResponse(sock, method="GET") + resp.begin() + self.assertEquals(resp.read(), 'hello world') + resp.close() + + for x in ('', 'foo\r\n'): + sock = FakeSocket(chunked_start + x) + resp = httplib.HTTPResponse(sock, method="GET") + resp.begin() + try: + resp.read() + except httplib.IncompleteRead, i: + self.assertEquals(i.partial, 'hello world') + else: + self.fail('IncompleteRead expected') + finally: + resp.close() + + class OfflineTest(TestCase): def test_responses(self): self.assertEquals(httplib.responses[httplib.NOT_FOUND], "Not Found") |