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

feat(static): set Content-Length for static file responses #1991

Merged
merged 7 commits into from
Nov 14, 2021

Conversation

vytas7
Copy link
Member

@vytas7 vytas7 commented Nov 13, 2021

Also fix range request support across different WSGI servers by always providing a Python wrapper without a file descriptor, since many sendfile implementations are buggy wrt not respecting the current file offset; both Gunicorn (benoitc/gunicorn#2669) and uWSGI are affected according to my testing.

There is still an open question remaining what to do with Meinheld: I've filed this as a separate issue (#1992).

@codecov
Copy link

codecov bot commented Nov 13, 2021

Codecov Report

Merging #1991 (ca4e279) into master (73b90c2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1991   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         6669      6674    +5     
  Branches      1079      1079           
=========================================
+ Hits          6669      6674    +5     
Impacted Files Coverage Δ
falcon/app.py 100.00% <ø> (ø)
falcon/routing/static.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73b90c2...ca4e279. Read the comment docs.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok. Just a test issue that I think would make sense changing before merging

Also don't we also miss the asgi tests?

tests/test_wsgi_servers.py Show resolved Hide resolved
@vytas7
Copy link
Member Author

vytas7 commented Nov 14, 2021

We already have unit tests covering ASGI too, but I will check if all the functionality is verified in unit tests as well.

Otherwise, ASGI has no concept of sendfile, and the response is rendered purely by the app, so adequate unit testing should be enough.

CaselIT
CaselIT previously approved these changes Nov 14, 2021
# Ignore Range headers for zero-byte files; just serve the empty body
# since Content-Range can't be used to express a zero-byte body
return fh, None
# NOTE(tipabu): Ignore Range headers for zero-byte files; just serve
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: @tipabu I prefixed your comments with your GH nick, and refactored the code slightly to work around issues with buggy sendfile implementations in many popular WSGI servers such as Gunicorn, uWSGI, etc.

@vytas7 vytas7 merged commit a6cd7db into falconry:master Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants