]> granicus.if.org Git - python/commitdiff
Merged revisions 87797 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 6 Jan 2011 17:18:32 +0000 (17:18 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 6 Jan 2011 17:18:32 +0000 (17:18 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87797 | antoine.pitrou | 2011-01-06 18:17:04 +0100 (jeu., 06 janv. 2011) | 4 lines

  Issue #3839: wsgiref should not override a Content-Length header set by
  the application.  Initial patch by Clovis Fabricio.
........

Lib/test/test_wsgiref.py
Lib/wsgiref/handlers.py
Misc/ACKS
Misc/NEWS

index ef38d77821a09a03b87232772a7733888fcdd336..345016399756f4a544afbec934a1314dd8c323f7 100755 (executable)
@@ -543,6 +543,11 @@ class HandlerTests(TestCase):
             s('200 OK',[])
             return ['\u0442\u0435\u0441\u0442'.encode("utf-8")]
 
+        def trivial_app4(e,s):
+            # Simulate a response to a HEAD request
+            s('200 OK',[('Content-Length', '12345')])
+            return []
+
         h = TestHandler()
         h.run(trivial_app1)
         self.assertEqual(h.stdout.getvalue(),
@@ -566,10 +571,12 @@ class HandlerTests(TestCase):
             b'\r\n'
             b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82')
 
-
-
-
-
+        h = TestHandler()
+        h.run(trivial_app4)
+        self.assertEqual(h.stdout.getvalue(),
+            b'Status: 200 OK\r\n'
+            b'Content-Length: 12345\r\n'
+            b'\r\n')
 
     def testBasicErrorOutput(self):
 
index 8a78eecf20e4ef88b47e1b8d66b66ffd557f6a24..4a771374519528d79126a7cdbccabb3bd00b5ab4 100644 (file)
@@ -240,7 +240,9 @@ class BaseHandler:
     def finish_content(self):
         """Ensure headers and content have both been sent"""
         if not self.headers_sent:
-            self.headers['Content-Length'] = "0"
+            # Only zero Content-Length if not set by the application (so
+            # that HEAD requests can be satisfied properly, see #3839)
+            self.headers.setdefault('Content-Length', "0")
             self.send_headers()
         else:
             pass # XXX check if content-length was too short?
index ef5fce89ff0ce3f645a6c86259505b8ab379de9d..ae2d3a52064fc5efaaf37e7370f7d4519ac13cb5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -237,6 +237,7 @@ Paul Everitt
 David Everly
 Greg Ewing
 Martijn Faassen
+Clovis Fabricio
 Andreas Faerber
 Bill Fancher
 Troy J. Farrell
index 1470351f21b99c19eb9e8d1e6bb6f4ffc4c5867b..a7b49de66d14df6ca30d271d80a8c5a9773c56bb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #3839: wsgiref should not override a Content-Length header set by
+  the application.  Initial patch by Clovis Fabricio.
+
 - Issue #10790: email.header.Header.append's charset logic now works correctly
   for charsets whose output codec is different from its input codec.