File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -520,6 +520,11 @@ def trivial_app3(e,s):
520520 s ('200 OK' ,[])
521521 return ['\u0442 \u0435 \u0441 \u0442 ' .encode ("utf-8" )]
522522
523+ def trivial_app4 (e ,s ):
524+ # Simulate a response to a HEAD request
525+ s ('200 OK' ,[('Content-Length' , '12345' )])
526+ return []
527+
523528 h = TestHandler ()
524529 h .run (trivial_app1 )
525530 self .assertEqual (h .stdout .getvalue (),
@@ -543,10 +548,12 @@ def trivial_app3(e,s):
543548 b'\r \n '
544549 b'\xd1 \x82 \xd0 \xb5 \xd1 \x81 \xd1 \x82 ' )
545550
546-
547-
548-
549-
551+ h = TestHandler ()
552+ h .run (trivial_app4 )
553+ self .assertEqual (h .stdout .getvalue (),
554+ b'Status: 200 OK\r \n '
555+ b'Content-Length: 12345\r \n '
556+ b'\r \n ' )
550557
551558 def testBasicErrorOutput (self ):
552559
Original file line number Diff line number Diff line change @@ -302,7 +302,9 @@ def sendfile(self):
302302 def finish_content (self ):
303303 """Ensure headers and content have both been sent"""
304304 if not self .headers_sent :
305- self .headers ['Content-Length' ] = "0"
305+ # Only zero Content-Length if not set by the application (so
306+ # that HEAD requests can be satisfied properly, see #3839)
307+ self .headers .setdefault ('Content-Length' , "0" )
306308 self .send_headers ()
307309 else :
308310 pass # XXX check if content-length was too short?
Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ Paul Everitt
261261David Everly
262262Greg Ewing
263263Martijn Faassen
264+ Clovis Fabricio
264265Andreas Faerber
265266Bill Fancher
266267Troy J. Farrell
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ Core and Builtins
3030Library
3131-------
3232
33+ - Issue #3839: wsgiref should not override a Content-Length header set by
34+ the application. Initial patch by Clovis Fabricio.
35+
3336- Issue #10492: bdb.Bdb.run() only traces the execution of the code, not the
3437 compilation (if the input is a string).
3538
You can’t perform that action at this time.
0 commit comments