Skip to content

Support returning Not Modified responses in FileResponse #2955

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulo-raca
Copy link

Summary

Looking at the souce for StaticFiles, it verifies the timestamp/etag and returns HTTP 304 - Not Modified when appropriate.

IMHO it would be simpler / more reusable if this was part of FileResponse.

(I brought this up a few hours ago in #2954, and decided to give it a try)

I haven't written new tests: There already is a ton of them and there is good coverage.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@paulo-raca paulo-raca force-pushed the FileResponseNotModified branch from d6d6c2b to 63b8950 Compare June 25, 2025 23:39
@paulo-raca paulo-raca force-pushed the FileResponseNotModified branch from 63b8950 to 8b9e306 Compare June 25, 2025 23:51
@Kludex Kludex requested review from abersheeran June 26, 2025 09:20
@Kludex
Copy link
Member

Kludex commented Jun 26, 2025

@abersheeran I know you've played a lot with this. Does this PR make sense?

"Not Modified" response could be returned instead.
"""
if http_if_none_match is not None:
match = [tag.strip(" W/") for tag in http_if_none_match.split(",")]
Copy link
Member

Choose a reason for hiding this comment

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

There are some issues here; the strong and weak semantics of etag should not be handled this way.

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.

3 participants