diff options
| author | Georg Brandl <georg@python.org> | 2008-02-24 00:14:24 +0000 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2008-02-24 00:14:24 +0000 |
| commit | 8c460d52417e764fc21362087b9314dbc09039bd (patch) | |
| tree | d2b4cf3f5bfed14bcbc5a04b52b8b0ad79364449 | |
| parent | 2363503074a3f1c2dbe934bed0c865d326e34c1a (diff) | |
| download | cpython-git-8c460d52417e764fc21362087b9314dbc09039bd.tar.gz | |
#1627: httplib now ignores negative Content-Length headers.
| -rw-r--r-- | Lib/httplib.py | 3 | ||||
| -rw-r--r-- | Lib/test/test_httplib.py | 7 | ||||
| -rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index bb4b59e701..5696467bd1 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -438,6 +438,9 @@ class HTTPResponse: self.length = int(length) except ValueError: self.length = None + else: + if self.length < 0: # ignore nonsensical negative lengths + self.length = None else: self.length = None diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index e9dd9d66c3..67719fd5e0 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -184,6 +184,13 @@ class BasicTest(TestCase): finally: 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): def test_responses(self): @@ -441,6 +441,8 @@ Core and builtins Library ------- +- #1627: httplib now ignores negative Content-Length headers. + - #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. |
