Skip to content
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

Cache Control: Conditional Request and 304 Response Support #2484

Closed
ChihweiLHBird opened this issue Jun 23, 2022 · 0 comments · Fixed by #2526
Closed

Cache Control: Conditional Request and 304 Response Support #2484

ChihweiLHBird opened this issue Jun 23, 2022 · 0 comments · Fixed by #2526

Comments

@ChihweiLHBird
Copy link
Member

ChihweiLHBird commented Jun 23, 2022

A previous PR provides cache-control HTTP header to file function in Sanic, but the best practice is to also implement the etag and the file validator.

Correct me if I am wrong:
With cache control value of no-cache, a validation is required every time before the client using the cached value. As my observation, validation request is usually a conditional request (requests that contain an If-None-Match or an If-Modified-Since header) to the resource URL. If the cached content is validated and the HTTP method is GET or HEAD, a 304 Not Modified response can be sent to the client, which is faster and smaller because it doesn't have to contain the file in the body. Validation is checking the conditions in a conditional request.

I think Sanic already supports 304 response in static file. I am wondering if we can do the same for file response in a general route handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant