#1627: httplib now ignores negative Content-Length headers.
diff --git a/Lib/httplib.py b/Lib/httplib.py
index bb4b59e..5696467 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -438,6 +438,9 @@
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 e9dd9d6..67719fd 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -184,6 +184,13 @@
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):