Skip to content

Commit

Permalink
Only set cache defaults on cacheable pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nottrobin committed Mar 29, 2021
1 parent fbef41e commit 4ce7a8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 6 additions & 2 deletions canonicalwebteam/flask_base/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def set_cache_control_headers(response):
# Our status endpoints need to be uncached
# to report accurate information at all times
response.cache_control.no_store = True
response.cache_control.max_age = 0

elif response.status_code == 200:
elif (
response.status_code == 200
and not response.cache_control.no_store
and not response.cache_control.no_cache
and not response.cache_control.private
):
# Normal responses, where the cache-control object hasn't
# been independently modified, should:

Expand Down
4 changes: 1 addition & 3 deletions tests/test_flask_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def test_status_endpoints(self):
response = client.get("_status/check")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data.decode(), "a-build-id")
self.assertEqual(
response.headers.get("Cache-Control"), "no-store, max-age=0"
)
self.assertEqual(response.headers.get("Cache-Control"), "no-store")

def test_redirects_deleted(self):
"""
Expand Down

0 comments on commit 4ce7a8a

Please sign in to comment.