zmiany w acl
This commit is contained in:
parent
1a62bbae2a
commit
6935cefaf7
26
app.py
26
app.py
@ -331,49 +331,41 @@ def create_admin_account():
|
|||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def apply_headers(response):
|
def apply_headers(response):
|
||||||
gc = get_global_config()
|
# Nagłówki niestandardowe
|
||||||
|
|
||||||
custom_headers = app.config.get("ADD_HEADERS", {})
|
custom_headers = app.config.get("ADD_HEADERS", {})
|
||||||
if isinstance(custom_headers, dict):
|
if isinstance(custom_headers, dict):
|
||||||
for header, value in custom_headers.items():
|
for header, value in custom_headers.items():
|
||||||
response.headers[header] = str(value)
|
response.headers[header] = str(value)
|
||||||
|
|
||||||
|
# Wykluczenia
|
||||||
if response.status_code in (301, 302, 303, 307, 308):
|
if response.status_code in (301, 302, 303, 307, 308):
|
||||||
response.headers.pop("Vary", None)
|
response.headers.pop("Vary", None)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if request.endpoint == 'robots':
|
|
||||||
return response
|
|
||||||
|
|
||||||
if 400 <= response.status_code < 500:
|
if 400 <= response.status_code < 500:
|
||||||
response.headers["Cache-Control"] = "no-store"
|
response.headers["Cache-Control"] = "no-store"
|
||||||
response.headers["Content-Type"] = "text/html; charset=utf-8"
|
response.headers["Content-Type"] = "text/html; charset=utf-8"
|
||||||
response.headers.pop("Vary", None)
|
response.headers.pop("Vary", None)
|
||||||
|
|
||||||
elif 500 <= response.status_code < 600:
|
elif 500 <= response.status_code < 600:
|
||||||
response.headers["Cache-Control"] = "no-store"
|
response.headers["Cache-Control"] = "no-store"
|
||||||
response.headers["Content-Type"] = "text/html; charset=utf-8"
|
response.headers["Content-Type"] = "text/html; charset=utf-8"
|
||||||
response.headers["Retry-After"] = "120"
|
response.headers["Retry-After"] = "120"
|
||||||
response.headers.pop("Vary", None)
|
response.headers.pop("Vary", None)
|
||||||
|
|
||||||
elif request.path.startswith("/admin"):
|
elif request.path.startswith("/admin"):
|
||||||
response.headers.pop("Vary", None)
|
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:
|
else:
|
||||||
response.headers["Vary"] = "Cookie, Accept-Encoding"
|
response.headers["Vary"] = "Cookie, Accept-Encoding"
|
||||||
cache_control_value = getattr(gc, "cache_control", None) or "private, max-age=0"
|
default_cache = app.config.get("CACHE_CONTROL_HEADER") or "private, max-age=0"
|
||||||
response.headers["Cache-Control"] = cache_control_value
|
response.headers["Cache-Control"] = default_cache
|
||||||
|
|
||||||
|
# Blokowanie botów
|
||||||
if app.config.get("BLOCK_BOTS", False):
|
if app.config.get("BLOCK_BOTS", False):
|
||||||
cc = app.config.get("CACHE_CONTROL_HEADER")
|
cc = app.config.get("CACHE_CONTROL_HEADER") or "no-store, no-cache, must-revalidate, max-age=0"
|
||||||
if cc:
|
pragma = app.config.get("PRAGMA_HEADER") or "no-cache"
|
||||||
response.headers["Cache-Control"] = cc
|
response.headers["Cache-Control"] = cc
|
||||||
response.headers.pop("Pragma", None)
|
response.headers["Pragma"] = pragma
|
||||||
else:
|
response.headers["X-Robots-Tag"] = app.config.get("ROBOTS_TAG") or "noindex, nofollow, nosnippet, noarchive"
|
||||||
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
|
||||||
response.headers["Pragma"] = app.config.get("PRAGMA_HEADER", "no-cache")
|
|
||||||
response.headers["X-Robots-Tag"] = app.config.get("ROBOTS_TAG", "noindex, nofollow, nosnippet, noarchive")
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user