Commits

Robert Brewer committed 124d864

Fixed some problems with redirect after staticdir.

  • Participants
  • Parent commits 233e580

Comments (0)

Files changed (2)

cherrypy/_cperror.py

                    307: "This resource has moved temporarily to <a href='%s'>%s</a>.",
                    }[status]
             response.body = "<br />\n".join([msg % (u, u) for u in self.urls])
+            # Previous code may have set C-L, so we have to reset it
+            # (allow finalize to set it).
+            response.headers.pop('Content-Length', None)
         elif status == 304:
             # Not Modified.
             # "The response MUST include the following header fields:
             
             # "The 304 response MUST NOT contain a message-body."
             response.body = None
+            # Previous code may have set C-L, so we have to reset it.
+            response.headers.pop('Content-Length', None)
         elif status == 305:
             # Use Proxy.
             # self.urls[0] should be the URI of the proxy.
             response.headers['Location'] = self.urls[0]
             response.body = None
+            # Previous code may have set C-L, so we have to reset it.
+            response.headers.pop('Content-Length', None)
         else:
             raise ValueError("The %s status code is unknown." % status)
     

cherrypy/test/test_static.py

         # The same page should be returned even if redirected.
         self.getPage("/docroot")
         self.assertStatus((302, 303))
+        self.assertHeader('Location', '%s/docroot/' % self.base())
+        self.assertBody("This resource can be found at <a href='%s/docroot/'>"
+                        "%s/docroot/</a>." % (self.base(), self.base()))
         
         # Check that we get an error if no .file or .dir
         self.getPage("/error/thing.html")