StaticFiles: Fix cache validation bug for deleted files in html mode #1023
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:app
and 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
.