[Python-checkins] r61035 - in python/trunk: Lib/httplib.py Lib/test/test_httplib.py Misc/NEWS

georg.brandl python-checkins at python.org
Sun Feb 24 01:14:24 CET 2008


Author: georg.brandl
Date: Sun Feb 24 01:14:24 2008
New Revision: 61035

Modified:
   python/trunk/Lib/httplib.py
   python/trunk/Lib/test/test_httplib.py
   python/trunk/Misc/NEWS
Log:
#1627: httplib now ignores negative Content-Length headers.


Modified: python/trunk/Lib/httplib.py
==============================================================================
--- python/trunk/Lib/httplib.py	(original)
+++ python/trunk/Lib/httplib.py	Sun Feb 24 01:14:24 2008
@@ -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
 

Modified: python/trunk/Lib/test/test_httplib.py
==============================================================================
--- python/trunk/Lib/test/test_httplib.py	(original)
+++ python/trunk/Lib/test/test_httplib.py	Sun Feb 24 01:14:24 2008
@@ -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):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Feb 24 01:14:24 2008
@@ -441,6 +441,8 @@
 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.


More information about the Python-checkins mailing list