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

No default cache headers on OPTION request #5042

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions geoportal/c2cgeoportal_geoportal/lib/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,26 @@ def set_common_headers(
if response is None:
response = request.response

if cache == NO_CACHE:
response.cache_control.no_cache = True
response.cache_control.max_age = 0
elif cache == PUBLIC_CACHE:
response.cache_control.public = True
elif cache == PRIVATE_CACHE:
if request.user is not None:
response.cache_control.private = True
else:
if request.method != "OPTIONS":
if cache == NO_CACHE:
response.cache_control.no_cache = True
response.cache_control.max_age = 0
elif cache == PUBLIC_CACHE:
response.cache_control.public = True
else: # pragma: no cover
raise "Invalid cache type"
elif cache == PRIVATE_CACHE:
if request.user is not None:
response.cache_control.private = True
else:
response.cache_control.public = True
else: # pragma: no cover
raise "Invalid cache type"

response.headers["Vary"] = set(["Accept-Encoding"])
if hasattr(request, "registry"):
headers_settings = request.registry.settings.get("headers", {})
service_headers_settings = headers_settings.get(service_name, {})

if cache != NO_CACHE:
if cache != NO_CACHE and request.method != "OPTIONS":
max_age = service_headers_settings.get("cache_control_max_age", 3600)

response.cache_control.max_age = max_age
Expand All @@ -209,7 +210,7 @@ def set_common_headers(
credentials, response
)

if vary:
if vary and request.method != "OPTIONS":
response.headers["Vary"].add("Accept-Language")

response.headers["Vary"] = ", ".join(response.headers["Vary"])
Expand Down