serowwanie staticow fix

This commit is contained in:
Mateusz Gruszczyński
2025-08-28 11:55:00 +02:00
parent 248d1dcd84
commit d42ce7fcc4
3 changed files with 22 additions and 11 deletions

25
app.py
View File

@@ -429,6 +429,15 @@ def apply_headers(response):
for header, value in custom_headers.items():
response.headers[header] = str(value)
if request.path.startswith("/static/"):
response.headers.pop("Content-Disposition", None)
response.headers["Vary"] = "Accept-Encoding"
response.headers["Cache-Control"] = app.config.get("CACHE_CONTROL_HEADER_STATIC")
if app.config.get("USE_ETAGS", True) and "ETag" not in response.headers:
response.add_etag()
response.make_conditional(request)
return response
# Wykluczenia
if response.status_code in (301, 302, 303, 307, 308):
response.headers.pop("Vary", None)
@@ -445,21 +454,17 @@ def apply_headers(response):
response.headers.pop("Vary", None)
elif request.path.startswith("/admin"):
response.headers.pop("Vary", None)
response.headers["Cache-Control"] = (
"no-store, no-cache, must-revalidate, max-age=0"
)
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
else:
response.headers["Vary"] = "Cookie, Accept-Encoding"
default_cache = app.config.get("CACHE_CONTROL_HEADER") or "private, max-age=0"
response.headers["Cache-Control"] = default_cache
# Blokowanie botów
if app.config.get("BLOCK_BOTS", False):
cc = (
app.config.get("CACHE_CONTROL_HEADER")
or "no-store, no-cache, must-revalidate, max-age=0"
)
response.headers["Cache-Control"] = cc
# Blokowanie botów (ale NIE dla /static/)
if app.config.get("BLOCK_BOTS", False) and not request.path.startswith("/static/"):
cc_override = app.config.get("CACHE_CONTROL_HEADER")
if cc_override:
response.headers["Cache-Control"] = cc_override
response.headers["X-Robots-Tag"] = (
app.config.get("ROBOTS_TAG") or "noindex, nofollow, nosnippet, noarchive"
)