]> granicus.if.org Git - python/commitdiff
Merged revisions 87797 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 6 Jan 2011 17:19:05 +0000 (17:19 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 6 Jan 2011 17:19:05 +0000 (17:19 +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 5866efc084cb1243a291acce3c4e8f405cfd69fc..45ca620c3a3ff9b0c65bc633bd7b4b106efb5714 100644 (file)
@@ -481,6 +481,11 @@ class HandlerTests(TestCase):
             s('200 OK',[])(e['wsgi.url_scheme'])
             return []
 
+        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(),
@@ -497,10 +502,12 @@ class HandlerTests(TestCase):
             "http")
 
 
-
-
-
-
+        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 a5f7109c266e5008376560544780532334c4cd57..ae1e8cc4371b44a91b3afa064e3d130733834f56 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 fbe650d57f6995bbfdd86eb450ecc1f4585cbadc..aca3873d7ced86db9a5ee19e9c79a528a28a162d 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -242,6 +242,7 @@ Paul Everitt
 David Everly
 Greg Ewing
 Martijn Faassen
+Clovis Fabricio
 Andreas Faerber
 Bill Fancher
 Troy J. Farrell
index 3d199746848caae8651fce75e90b9f53f0d3e17c..1ac5985059620f78099919d3eb193007cbadad08 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,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 #10806, issue #9905: Fix subprocess pipes when some of the standard
   file descriptors (0, 1, 2) are closed in the parent process.  Initial
   patch by Ross Lagerwall.