MCPcopy
hub / github.com/pallets/flask / finalize_request

Method finalize_request

src/flask/app.py:922–951  ·  view source on GitHub ↗

Given the return value from a view function this finalizes the request by converting it into a response and invoking the postprocessing functions. This is invoked for both normal request dispatching as well as error handlers. Because this means that it might be call

(
        self,
        rv: ft.ResponseReturnValue | HTTPException,
        from_error_handler: bool = False,
    )

Source from the content-addressed store, hash-verified

920 return self.finalize_request(rv)
921
922 def finalize_request(
923 self,
924 rv: ft.ResponseReturnValue | HTTPException,
925 from_error_handler: bool = False,
926 ) -> Response:
927 """Given the return value from a view function this finalizes
928 the request by converting it into a response and invoking the
929 postprocessing functions. This is invoked for both normal
930 request dispatching as well as error handlers.
931
932 Because this means that it might be called as a result of a
933 failure a special safe mode is available which can be enabled
934 with the `from_error_handler` flag. If enabled, failures in
935 response processing will be logged and otherwise ignored.
936
937 :internal:
938 """
939 response = self.make_response(rv)
940 try:
941 response = self.process_response(response)
942 request_finished.send(
943 self, _async_wrapper=self.ensure_sync, response=response
944 )
945 except Exception:
946 if not from_error_handler:
947 raise
948 self.logger.exception(
949 "Request finalizing failed with an error while handling an error"
950 )
951 return response
952
953 def make_default_options_response(self) -> Response:
954 """This method is called to create the default ``OPTIONS`` response.

Callers 2

handle_exceptionMethod · 0.95
full_dispatch_requestMethod · 0.95

Calls 2

make_responseMethod · 0.95
process_responseMethod · 0.95

Tested by

no test coverage detected