mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
#1627: httplib now ignores negative Content-Length headers.
This commit is contained in:
parent
2363503074
commit
8c460d5241
3 changed files with 12 additions and 0 deletions
|
|
@ -438,6 +438,9 @@ class HTTPResponse:
|
||||||
self.length = int(length)
|
self.length = int(length)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.length = None
|
self.length = None
|
||||||
|
else:
|
||||||
|
if self.length < 0: # ignore nonsensical negative lengths
|
||||||
|
self.length = None
|
||||||
else:
|
else:
|
||||||
self.length = None
|
self.length = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,13 @@ class BasicTest(TestCase):
|
||||||
finally:
|
finally:
|
||||||
resp.close()
|
resp.close()
|
||||||
|
|
||||||
|
def test_negative_content_length(self):
|
||||||
|
sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n')
|
||||||
|
resp = httplib.HTTPResponse(sock, method="GET")
|
||||||
|
resp.begin()
|
||||||
|
self.assertEquals(resp.read(), 'Hello\r\n')
|
||||||
|
resp.close()
|
||||||
|
|
||||||
|
|
||||||
class OfflineTest(TestCase):
|
class OfflineTest(TestCase):
|
||||||
def test_responses(self):
|
def test_responses(self):
|
||||||
|
|
|
||||||
|
|
@ -441,6 +441,8 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- #1627: httplib now ignores negative Content-Length headers.
|
||||||
|
|
||||||
- #900744: If an invalid chunked-encoding header is sent by a server,
|
- #900744: If an invalid chunked-encoding header is sent by a server,
|
||||||
httplib will now raise IncompleteRead and close the connection instead
|
httplib will now raise IncompleteRead and close the connection instead
|
||||||
of raising ValueError.
|
of raising ValueError.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue