Skip to content

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
Owner

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
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

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

What's wrong with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

W/ (case-sensitive) indicates that a weak validator is used. Weak ETags are easy to generate, but are far less useful for comparisons. Strong validators are ideal for comparisons but can be very difficult to generate efficiently. Weak ETag values of two representations of the same resources might be semantically equivalent, but not byte-for-byte identical. This means weak ETags prevent caching when byte range requests are used, but strong ETags mean range requests can still be cached.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag

When requesting a range, different handling is required. However, this difference has been ignored here.

@Smixi-syn
Copy link
Contributor

Hello, is this related to #2891 ?

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.

4 participants