New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"on_end_request" hook is getting called before the response header is sent #1404

bb-migration opened this Issue Jan 29, 2016 · 2 comments


2 participants

bb-migration commented Jan 29, 2016

Originally reported by: ronin8600 (Bitbucket: ronin8600, GitHub: ronin8600)

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.



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)
            cl = int(self.inheaders.get(b"Content-Length", 0))
            if mrbs and mrbs < cl:
                if not self.sent_headers:
                        "413 Request Entity Too Large",
                        "The entity sent with the request exceeds the "
                        "maximum allowed bytes.")
            self.rfile = KnownLengthRFile(self.conn.rfile, cl)

        # This will cause the "on_end_request" hook to be called before the headers are sent below

        if (self.ready and not self.sent_headers):
            self.sent_headers = True
        if self.chunked_write:


This comment has been minimized.

bb-migration commented Jan 30, 2016

Original comment by ronin8600 (Bitbucket: ronin8600, GitHub: ronin8600):

Proposed changes in pull request (


This comment has been minimized.


webknjaz commented Feb 9, 2018

/cc: @moigagoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment