Skip to content
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

[24.0] Reset content-length for unhandled exceptions #18233

Conversation

mvdbeek
Copy link
Member

@mvdbeek mvdbeek commented May 27, 2024

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 if you apply the diff below and navigate to http://127.0.0.1:8080/dataset/imp.

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>"

(Please replace this header with a description of your pull request. Please include BOTH what you did and why you made the changes. The "why" may simply be citing a relevant Galaxy issue.)
(If fixing a bug, please add any relevant error or traceback)
(For UI components, it is recommended to include screenshots or screencasts)

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

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>"

```
@mvdbeek mvdbeek merged commit 316eb5b into galaxyproject:release_24.0 May 27, 2024
52 checks passed
@jdavcs jdavcs added this to the 24.1 milestone Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants