-
-
Notifications
You must be signed in to change notification settings - Fork 947
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): implement Etag rendering for static files #2333
base: master
Are you sure you want to change the base?
feat(static): implement Etag rendering for static files #2333
Conversation
I still have to go through the docs to see if any updates are needed there. As of now, I want to check with you if that's the intended implementation. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2333 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 7726 7749 +23
Branches 1071 1074 +3
=========================================
+ Hits 7726 7749 +23 ☔ View full report in Codecov by Sentry. |
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.
As I understand, this is work-in-progress, so I didn't review the details, just provided general feedback on how we want to only call fstat()
once per file.
falcon.ETag: ETag generated for the file using its modification time and size. | ||
""" | ||
fh = io.open(file_path, 'rb') | ||
content_length = os.fstat(fh.fileno()).st_size |
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.
We don't want to run os.fstat()
multiple times on the same file handle as it is a real syscall.
We only want to call it once per serving, and save the result in a variable.
try: | ||
if self._fallback_filename is None: | ||
raise falcon.HTTPNotFound() | ||
etag = _generate_etag(self._fallback_filename) |
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.
Same as above, we are already calling fstat
and handling potential errors elsewhere in this file, we can just reuse the same result.
Summary of Changes
If_None_Match
header is present in Requests's headers and its ETag matches the file's ETag anHTTP_304
status code is returned.Related Issues
#2243
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
, with the file name format{issue_number}.{fragment_type}.rst
. (Runtowncrier --draft
to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.