StaticFiles: Fix cache validation bug for deleted files in html mode#1023
Merged
JayH5 merged 3 commits intoKludex:masterfrom Feb 5, 2021
Merged
StaticFiles: Fix cache validation bug for deleted files in html mode#1023JayH5 merged 3 commits intoKludex:masterfrom
JayH5 merged 3 commits intoKludex:masterfrom
Conversation
Previously StaticFiles would return 304 for a deleted file if its Last-Modified date was the same as that of 404.html
JayH5
approved these changes
Feb 5, 2021
Contributor
JayH5
left a comment
There was a problem hiding this comment.
Thanks, this seems like a potentially quite frustrating bug 😓
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, when StaticFiles(html=True) fails to find the requested file and decides to return the 404 error page, it compares the If-Modified-Since of the requested file with the Last-Modified of 404.html. Therefore, if a requested file was deleted but has had the same Last-Modified as that of 404.html, StaticFiles would still return 304 Not Modified, while the logical behavior is to return the error page.
To reproduce the issue manually, create the app and the html files:
(I will assume some.html and 404.html have the same Last-Modified, since they are created by the same command); then start
main:appand open some.html in the browser. If you then delete some.html and reload the page, the file should still be there.This PR fixes the issue by returning the 404 response directly from
StaticFiles.get_response, rather then callingStaticFiles.file_response.