Skip to content

Commit

Permalink
Reset content-length for unhandled exceptions
Browse files Browse the repository at this point in the history
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"<a href='{escape(referer)}'>return to the previous page</a>"

```
  • Loading branch information
mvdbeek committed May 27, 2024
1 parent d8b827f commit 3c6a9a8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/galaxy/web/framework/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3c6a9a8

Please sign in to comment.