Skip to content
Browse files

πŸ› Fix caching headers on main view

Clients/browsers should be instructed to always revalidate against the
server in order to prevent any kind of old content to be served.

  • Loading branch information
foosel committed Mar 4, 2019
1 parent bc66d29 commit ceade46dd782c3685242788124639067ac91061e
Showing with 19 additions and 1 deletion.
  1. +18 βˆ’1 src/octoprint/server/util/
  2. +1 βˆ’0 src/octoprint/server/
@@ -780,7 +780,7 @@ def cache_check_response_headers(response):

headers = response.headers

if "Cache-Control" in headers and "no-cache" in headers["Cache-Control"]:
if "Cache-Control" in headers and ("no-cache" in headers["Cache-Control"] or "no-store" in headers["Cache-Control"]):
return True

if "Pragma" in headers and "no-cache" in headers["Pragma"]:
@@ -1049,6 +1049,18 @@ def decorated_function(*args, **kwargs):
return decorator

def with_client_revalidation(f):
def decorated_function(*args, **kwargs):
r = f(*args, **kwargs)

if isinstance(r, flask.Response):
r = add_revalidation_response_headers(r)

return r
return decorated_function

def with_revalidation_checking(etag_factory=None,
@@ -1129,6 +1141,11 @@ def check_lastmodified(lastmodified):
lastmodified >= flask.request.if_modified_since

def add_revalidation_response_headers(response):
response.headers["Cache-Control"] = "no-cache, must-revalidate"
return response

def add_non_caching_response_headers(response):
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
response.headers["Pragma"] = "no-cache"
@@ -308,6 +308,7 @@ def compute_etag(files=None, lastmodified=None, additional=None):
unless_response=lambda response: util.flask.cache_check_response_headers(response) or util.flask.cache_check_status_code(response, _valid_status_for_cache))(decorated_view)
decorated_view = util.flask.with_client_revalidation(decorated_view)
decorated_view = util.flask.conditional(check_etag_and_lastmodified, NOT_MODIFIED)(decorated_view)
return decorated_view

1 comment on commit ceade46


This comment has been minimized.

Copy link

GitIssueBot commented on ceade46 Mar 19, 2019

This commit has been mentioned on OctoPrint Community Forum. There might be relevant details there:

Please sign in to comment.
You can’t perform that action at this time.