Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
"on_end_request" hook is getting called before the response header is sent #1404
While debugging an issue with ws4py calling the connected callback before response headers were sent to the client I noticed a possible problem in when CherryPy calls the "on_end_request " hook. It appears that CherryPy is calling the "on_end_request" before it sends the response headers. I made a quick changed to delay calling close on the response in the gateway till after the headers are sent and it looks like it works for my ws4py test case.
#!python def respond(self): """Call the gateway and write its iterable output.""" mrbs = self.server.max_request_body_size if self.chunked_read: self.rfile = ChunkedRFile(self.conn.rfile, mrbs) else: cl = int(self.inheaders.get(b"Content-Length", 0)) if mrbs and mrbs < cl: if not self.sent_headers: self.simple_response( "413 Request Entity Too Large", "The entity sent with the request exceeds the " "maximum allowed bytes.") return self.rfile = KnownLengthRFile(self.conn.rfile, cl) # This will cause the "on_end_request" hook to be called before the headers are sent below self.server.gateway(self).respond() if (self.ready and not self.sent_headers): self.sent_headers = True self.send_headers() if self.chunked_write: self.conn.wfile.write(b"0\r\n\r\n")