diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-02-02 22:49:34 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-02-02 22:49:34 +0100 |
commit | beec61ae4e811f55f58d0197c8af994e252ab9ae (patch) | |
tree | 3a5a7b021457780e1f020297404f677e94ffc3c9 /Lib/test/test_httplib.py | |
parent | 637525718873f9c6571078e0201523438b17d341 (diff) | |
download | cpython-beec61ae4e811f55f58d0197c8af994e252ab9ae.tar.gz cpython-beec61ae4e811f55f58d0197c8af994e252ab9ae.zip |
Issue #15633: httplib.HTTPResponse is now mark closed when the server sends less than the advertised Content-Length.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index b0777d42867..5df4b512041 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -199,6 +199,19 @@ class BasicTest(TestCase): self.assertEqual(resp.read(1), b'') self.assertTrue(resp.isclosed()) + def test_partial_reads_incomplete_body(self): + # if the server shuts down the connection before the whole + # content-length is delivered, the socket is gracefully closed + body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + self.assertEqual(resp.read(2), b'Te') + self.assertFalse(resp.isclosed()) + self.assertEqual(resp.read(2), b'xt') + self.assertEqual(resp.read(1), b'') + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port @@ -349,7 +362,7 @@ class BasicTest(TestCase): resp = client.HTTPResponse(sock, method="GET") resp.begin() self.assertEqual(resp.read(), b'Hello\r\n') - resp.close() + self.assertTrue(resp.isclosed()) def test_incomplete_read(self): sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n') @@ -363,10 +376,9 @@ class BasicTest(TestCase): "IncompleteRead(7 bytes read, 3 more expected)") self.assertEqual(str(i), "IncompleteRead(7 bytes read, 3 more expected)") + self.assertTrue(resp.isclosed()) else: self.fail('IncompleteRead expected') - finally: - resp.close() def test_epipe(self): sock = EPipeSocket( |