1
0
mirror of synced 2024-11-30 16:54:30 +01:00

Add cache control headers to force unruly clients like android to reload REST responses every time.

This commit is contained in:
Jennifer Taylor 2020-04-27 23:31:59 +00:00
parent 069fbb4ba1
commit 479ba60b05
2 changed files with 20 additions and 0 deletions

View File

@ -46,6 +46,15 @@ def before_request() -> None:
g.authorized = g.data.local.api.validate_client(authtoken) g.authorized = g.data.local.api.validate_client(authtoken)
@app.after_request
def after_request(response: Response) -> Response:
# Make sure our REST responses don't get cached, so that remote
# servers which respect cache headers don't get confused.
response.cache_control.no_cache = True
response.cache_control.must_revalidate = True
response.cache_control.private = True
@app.teardown_request @app.teardown_request
def teardown_request(exception: Any) -> None: def teardown_request(exception: Any) -> None:
data = getattr(g, 'data', None) data = getattr(g, 'data', None)

View File

@ -47,6 +47,17 @@ def before_request() -> None:
g.userID = None g.userID = None
@app.after_request
def after_request(response: Response) -> Response:
if not response.cache_control.max_age:
# Make sure our REST calls don't get cached, so that the
# live pages update in real-time.
response.cache_control.no_cache = True
response.cache_control.must_revalidate = True
response.cache_control.private = True
return response
@app.teardown_request @app.teardown_request
def teardown_request(exception: Any) -> None: def teardown_request(exception: Any) -> None:
data = getattr(g, 'data', None) data = getattr(g, 'data', None)