diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-15 18:22:30 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-15 18:22:30 (GMT) |
commit | d20e7745eeb99c5f2089b5b6ffa351658cb4e839 (patch) | |
tree | 018ae0d638f113f4c06ac52db5c9e50a1f0e8378 /Lib/test/test_httplib.py | |
parent | 30505413df61f1cd7d550d6b90e08e691c62479a (diff) | |
parent | 084daa2f7492ae809b5ce09d2cdbad6ed5a71848 (diff) | |
download | cpython-d20e7745eeb99c5f2089b5b6ffa351658cb4e839.zip cpython-d20e7745eeb99c5f2089b5b6ffa351658cb4e839.tar.gz cpython-d20e7745eeb99c5f2089b5b6ffa351658cb4e839.tar.bz2 |
Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished.
Patch by Eran Rundstein.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index cf61552..5ebcfcb 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -175,7 +175,7 @@ class BasicTest(TestCase): self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') def test_partial_reads(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -187,7 +187,7 @@ class BasicTest(TestCase): self.assertTrue(resp.isclosed()) def test_partial_readintos(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -203,6 +203,38 @@ class BasicTest(TestCase): self.assertEqual(bytes(b), b'xt') self.assertTrue(resp.isclosed()) + def test_partial_reads_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\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_partial_readintos_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + b = bytearray(2) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'Te') + self.assertFalse(resp.isclosed()) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'xt') + n = resp.readinto(b) + self.assertEqual(n, 0) + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port |