Commits

Anonymous committed 0a885fd

- Set the cpg.response.wfile and the cpg.response.sendResponse attributes *before* calling initRequest. This way filters that are called on the input chain can access the information (specially wfile) that is needed.

- Also, made sure that the handleRequest call uses the value from cpg.response.wfile instead of the local wfile; this allows the filter to redirect or to wrap the original wfile and set the new one on cpg.response.wfile.

Comments (0)

Files changed (1)

cherrypy/_cphttptools.py

     applyFilterList('afterRequestBody')
 
 def doRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile):
+    # inits the cpg.responsed.wfile so filters can access it
+    cpg.response.wfile = wfile
+    cpg.response.sendResponse = 1
     initRequest(clientAddress, remoteHost, requestLine, headers, rfile, wfile)
+    # reads back wfile; if may be redirected by a filter
+    wfile = cpg.response.wfile
 
     # Prepare response variables
     now = time.time()
         "Content-Length": 0
     }
     cpg.response.simpleCookie = Cookie.SimpleCookie()
-    cpg.response.wfile = wfile
-    cpg.response.sendResponse = 1
 
     try:
         handleRequest(wfile)