mirror of
https://github.com/python/cpython.git
synced 2025-09-25 09:50:37 +00:00
Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished.
Patch by Eran Rundstein.
This commit is contained in:
parent
eea058b014
commit
4113d2bd36
4 changed files with 23 additions and 1 deletions
|
@ -565,6 +565,10 @@ class HTTPResponse:
|
||||||
self.length -= len(s)
|
self.length -= len(s)
|
||||||
if not self.length:
|
if not self.length:
|
||||||
self.close()
|
self.close()
|
||||||
|
else:
|
||||||
|
if not s:
|
||||||
|
self.close()
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _read_chunked(self, amt):
|
def _read_chunked(self, amt):
|
||||||
|
|
|
@ -166,7 +166,7 @@ class BasicTest(TestCase):
|
||||||
self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''')
|
self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''')
|
||||||
|
|
||||||
def test_partial_reads(self):
|
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()
|
# 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"
|
body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText"
|
||||||
sock = FakeSocket(body)
|
sock = FakeSocket(body)
|
||||||
|
@ -177,6 +177,19 @@ class BasicTest(TestCase):
|
||||||
self.assertEqual(resp.read(2), 'xt')
|
self.assertEqual(resp.read(2), 'xt')
|
||||||
self.assertTrue(resp.isclosed())
|
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 = httplib.HTTPResponse(sock)
|
||||||
|
resp.begin()
|
||||||
|
self.assertEqual(resp.read(2), 'Te')
|
||||||
|
self.assertFalse(resp.isclosed())
|
||||||
|
self.assertEqual(resp.read(2), 'xt')
|
||||||
|
self.assertEqual(resp.read(1), '')
|
||||||
|
self.assertTrue(resp.isclosed())
|
||||||
|
|
||||||
def test_host_port(self):
|
def test_host_port(self):
|
||||||
# Check invalid host_port
|
# Check invalid host_port
|
||||||
|
|
||||||
|
|
|
@ -849,6 +849,7 @@ Clinton Roy
|
||||||
Paul Rubin
|
Paul Rubin
|
||||||
Sam Ruby
|
Sam Ruby
|
||||||
Audun S. Runde
|
Audun S. Runde
|
||||||
|
Eran Rundstein
|
||||||
Rauli Ruohonen
|
Rauli Ruohonen
|
||||||
Jeff Rush
|
Jeff Rush
|
||||||
Sam Rushing
|
Sam Rushing
|
||||||
|
|
|
@ -160,6 +160,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #16298: In HTTPResponse.read(), close the socket when there is no
|
||||||
|
Content-Length and the incoming stream is finished. Patch by Eran
|
||||||
|
Rundstein.
|
||||||
|
|
||||||
- Issue #16248: Disable code execution from the user's home directory by
|
- Issue #16248: Disable code execution from the user's home directory by
|
||||||
tkinter when the -E flag is passed to Python. Patch by Zachary Ware.
|
tkinter when the -E flag is passed to Python. Patch by Zachary Ware.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue