-
Notifications
You must be signed in to change notification settings - Fork 684
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
Disable werkzeug header generation for files served via mod_xsendfile #7188
Conversation
5031c47
to
e0497ec
Compare
Looks good in dev env:
Now for the prod test. |
@@ -525,8 +525,13 @@ def col_download_all(cols_selected: List[str]) -> werkzeug.Response: | |||
|
|||
def serve_file_with_etag(db_obj: Union[Reply, Submission]) -> flask.Response: | |||
file_path = Storage.get_default().path(db_obj.source.filesystem_id, db_obj.filename) | |||
add_range_headers = not current_app.config["USE_X_SENDFILE"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining why we're doing this might be nice so we don't forget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid pushing further code changes I just beefed up the commit message. Please restamp if all looks well.
Shuttled the (TIL that you have to run Looks good there as well.
|
Response headers in prod look good as well:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and appears to work as intended! One suggestion inline, up to you. Other than that, should the title of this PR be "[2.9.0]" given that it is targeting develop
?
It's a 2.9.0 fix but I have no problem editing it |
(I may be out of date, I'm used to the convention of having the "[x.x.x]" in the PR title if it's a backport targeting a release branch.) |
For partial content requests, werkzeug's default behaviour is to calculate and add the necessary Content* headers in the response. However, mod-xsendfile, used by SD to deliver files more efficiently, will just pass through requests with pre-existing Content* headers, not even removing the X-Sendfile header used to invoke it. If USE_X_SENDIFLE is set to True in the Flask config, we should stop werkzeug from generating headers, and just let mod_xsendfile do it.
e0497ec
to
9969e12
Compare
[2.9.0] Backport #7188: Disable werkzeug header generation for files served via mod_xsendfile
Status
Draft mode
Description of Changes
Fixes #7186.
By default, when flask serves a file in response to a partial content request, it (or rather werkzeug) generates the necessary Content-length and Content-range headers itself. Production SD instances use mod_xsendfile to speed up downloads, but mod_xsendfile skips handling responses where said headers are already set.
This PR checks whether USE_X_SENDFILE is set, and if so, it disables extra header generation for partial content responses, allowing mod_xsendfile to handle them instead.
Testing
dev environment
make dev
prod environment (VMs ok)
How should the reviewer test this PR?
Write out any special testing steps here.
Deployment
Any special considerations for deployment? Consider both:
n/a
Checklist
If you made non-trivial code changes: