serowwanie staticow fix
This commit is contained in:
25
app.py
25
app.py
@@ -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"
|
||||
)
|
||||
|
Reference in New Issue
Block a user