[Python-checkins] r87797 - in python/branches/py3k: Lib/test/test_wsgiref.py Lib/wsgiref/handlers.py Misc/ACKS Misc/NEWS
antoine.pitrou
python-checkins at python.org
Thu Jan 6 18:17:04 CET 2011
Author: antoine.pitrou
Date: Thu Jan 6 18:17:04 2011
New Revision: 87797
Log:
Issue #3839: wsgiref should not override a Content-Length header set by
the application. Initial patch by Clovis Fabricio.
Modified:
python/branches/py3k/Lib/test/test_wsgiref.py
python/branches/py3k/Lib/wsgiref/handlers.py
python/branches/py3k/Misc/ACKS
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/test/test_wsgiref.py
==============================================================================
--- python/branches/py3k/Lib/test/test_wsgiref.py (original)
+++ python/branches/py3k/Lib/test/test_wsgiref.py Thu Jan 6 18:17:04 2011
@@ -520,6 +520,11 @@
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(),
@@ -543,10 +548,12 @@
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):
Modified: python/branches/py3k/Lib/wsgiref/handlers.py
==============================================================================
--- python/branches/py3k/Lib/wsgiref/handlers.py (original)
+++ python/branches/py3k/Lib/wsgiref/handlers.py Thu Jan 6 18:17:04 2011
@@ -302,7 +302,9 @@
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?
Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS (original)
+++ python/branches/py3k/Misc/ACKS Thu Jan 6 18:17:04 2011
@@ -261,6 +261,7 @@
David Everly
Greg Ewing
Martijn Faassen
+Clovis Fabricio
Andreas Faerber
Bill Fancher
Troy J. Farrell
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Thu Jan 6 18:17:04 2011
@@ -30,6 +30,9 @@
Library
-------
+- Issue #3839: wsgiref should not override a Content-Length header set by
+ the application. Initial patch by Clovis Fabricio.
+
- Issue #10492: bdb.Bdb.run() only traces the execution of the code, not the
compilation (if the input is a string).
More information about the Python-checkins
mailing list