fixup! fixup! ️(backend) implement etag and last_modified cache headers to fetch content
Some checks are pending
Helmfile lint / helmfile-lint (push) Waiting to run

This commit is contained in:
Anthony LC 2026-04-20 17:23:44 +02:00
parent 325f3ec9bb
commit 3d10f8d63d
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -1971,7 +1971,16 @@ class DocumentViewSet(
if_none_match = request.META.get("HTTP_IF_NONE_MATCH") # contains ETag
if_modified_since = request.META.get("HTTP_IF_MODIFIED_SINCE")
if if_none_match and if_none_match == etag:
# Normalize ETags for comparison: strip the W/ weak prefix and surrounding
# quotes. Proxies (e.g. nginx with gzip) convert strong ETags to weak ones,
# so a strict equality check would fail on production even when unchanged.
def _etag_value(tag):
if tag:
tag = tag.removeprefix("W/")
tag = tag.strip('"')
return tag
if if_none_match and _etag_value(if_none_match) == _etag_value(etag):
return drf_response.Response(status=status.HTTP_304_NOT_MODIFIED)
if if_modified_since:

View file

@ -487,6 +487,7 @@ class Base(Configuration):
"if-none-match",
"if-modified-since",
)
CORS_EXPOSE_HEADERS = ["ETag"]
# Sentry
SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN", environ_prefix=None)