Commit 59bf7388 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 87797 via svnmerge from

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.
........
parent 6e7d711d
...@@ -543,6 +543,11 @@ class HandlerTests(TestCase): ...@@ -543,6 +543,11 @@ class HandlerTests(TestCase):
s('200 OK',[]) s('200 OK',[])
return ['\u0442\u0435\u0441\u0442'.encode("utf-8")] 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 = TestHandler()
h.run(trivial_app1) h.run(trivial_app1)
self.assertEqual(h.stdout.getvalue(), self.assertEqual(h.stdout.getvalue(),
...@@ -566,10 +571,12 @@ class HandlerTests(TestCase): ...@@ -566,10 +571,12 @@ class HandlerTests(TestCase):
b'\r\n' b'\r\n'
b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82') 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): def testBasicErrorOutput(self):
......
...@@ -240,7 +240,9 @@ class BaseHandler: ...@@ -240,7 +240,9 @@ class BaseHandler:
def finish_content(self): def finish_content(self):
"""Ensure headers and content have both been sent""" """Ensure headers and content have both been sent"""
if not self.headers_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() self.send_headers()
else: else:
pass # XXX check if content-length was too short? pass # XXX check if content-length was too short?
......
...@@ -237,6 +237,7 @@ Paul Everitt ...@@ -237,6 +237,7 @@ Paul Everitt
David Everly David Everly
Greg Ewing Greg Ewing
Martijn Faassen Martijn Faassen
Clovis Fabricio
Andreas Faerber Andreas Faerber
Bill Fancher Bill Fancher
Troy J. Farrell Troy J. Farrell
......
...@@ -27,6 +27,9 @@ Core and Builtins ...@@ -27,6 +27,9 @@ Core and Builtins
Library 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 - Issue #10790: email.header.Header.append's charset logic now works correctly
for charsets whose output codec is different from its input codec. for charsets whose output codec is different from its input codec.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment