From 3c6a9a8eaf9e6451f31ffb74408aa0d28bdf2541 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 27 May 2024 11:17:13 +0200 Subject: [PATCH] Reset content-length for unhandled exceptions This prevents `ProtocolError` caused by the error middleware not being able to reset the content length. Only affects routes that explicitly set the content-length and don't have a default response handler. This is effectively the case when using `web.expose`. To test this, make sure you get Galaxy's error middleware output in the browser and your console. ``` diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index c95d9df788..92b04684d3 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -456,6 +456,8 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE def imp(self, trans, dataset_id=None, **kwd): """Import another user's dataset via a shared URL; dataset is added to user's current history.""" # Set referer message. + trans.response.headers["content-length"] = 0 + trans = None referer = trans.request.referer if referer and not referer.startswith(f"{trans.request.application_url}{url_for('/login')}"): referer_message = f"return to the previous page" ``` --- lib/galaxy/web/framework/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/galaxy/web/framework/base.py b/lib/galaxy/web/framework/base.py index 364e6d4c72e2..276ac0b52d5d 100644 --- a/lib/galaxy/web/framework/base.py +++ b/lib/galaxy/web/framework/base.py @@ -264,6 +264,7 @@ def handle_request(self, request_id, path_info, environ, start_response, body_re except Exception as e: body = self.handle_controller_exception(e, trans, method, **kwargs) if not body: + trans.response.headers.pop("content-length", None) raise body_renderer = body_renderer or self._render_body return body_renderer(trans, body, environ, start_response)