Commits

Robert Brewer committed 21f60da

Test and fix for #1055 (cherrypy.response.status is None during on_end_resource phase)

Comments (0)

Files changed (2)

cherrypy/_cprequest.py

         
         headers = self.headers
         
+        self.status = "%s %s" % (code, reason)
         self.output_status = ntob(str(code), 'ascii') + ntob(" ") + headers.encode(reason)
         
         if self.stream:

cherrypy/test/test_core.py

                 return cherrypy.url(path_info, relative=relative)
 
 
+        def log_status():
+            Status.statuses.append(cherrypy.response.status)
+        cherrypy.tools.log_status = cherrypy.Tool('on_end_resource', log_status)
+
+
         class Status(Test):
             
             def index(self):
             def bad(self):
                 cherrypy.response.status = "error"
                 return "bad news"
+            
+            statuses = []
+            def on_end_resource_stage(self):
+                return repr(self.statuses)
+            on_end_resource_stage._cp_config = {'tools.log_status.on': True}
 
 
         class Redirect(Test):
         self.assertStatus(500)
         msg = "Illegal response status from server ('error' is non-numeric)."
         self.assertErrorPage(500, msg)
-    
+
+    def test_on_end_resource_status(self):
+        self.getPage('/status/on_end_resource_stage')
+        self.assertBody('[]')
+        self.getPage('/status/on_end_resource_stage')
+        self.assertBody(repr(["200 OK"]))
+
     def testSlashes(self):
         # Test that requests for index methods without a trailing slash
         # get redirected to the same URI path with a trailing slash.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.