From 479ba60b0565f4f04014ccb7635fd16060eaee7f Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 27 Apr 2020 23:31:59 +0000 Subject: [PATCH] Add cache control headers to force unruly clients like android to reload REST responses every time. --- bemani/api/app.py | 9 +++++++++ bemani/frontend/app.py | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/bemani/api/app.py b/bemani/api/app.py index 9027938..1286d1e 100644 --- a/bemani/api/app.py +++ b/bemani/api/app.py @@ -46,6 +46,15 @@ def before_request() -> None: 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 def teardown_request(exception: Any) -> None: data = getattr(g, 'data', None) diff --git a/bemani/frontend/app.py b/bemani/frontend/app.py index 8d3d7c7..c968427 100644 --- a/bemani/frontend/app.py +++ b/bemani/frontend/app.py @@ -47,6 +47,17 @@ def before_request() -> 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 def teardown_request(exception: Any) -> None: data = getattr(g, 'data', None)