From 72167d14d2796e8527f09d183107fad99c0ab2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 2 Jul 2019 12:44:29 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20caching=20headers=20on=20/?= =?UTF-8?q?=20in=20case=20of=20wizards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revalidation header from ceade46dd782c3685242788124639067ac91061e was overwriting custom header in case of active wizards, causing the browser to cache HTML code with enabled wizards. This fixes this by checking if the headers in question actually need to be set and aren't already there. --- src/octoprint/server/util/flask.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index a5b5eace4..e8bf15133 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1143,7 +1143,14 @@ def check_lastmodified(lastmodified): def add_revalidation_response_headers(response): - response.headers["Cache-Control"] = "no-cache, must-revalidate" + import werkzeug.http + + cache_control = werkzeug.http.parse_dict_header(response.headers.get("Cache-Control", "")) + if "no-cache" not in cache_control: + cache_control["no-cache"] = None + if "must-revalidate" not in cache_control: + cache_control["must-revalidate"] = None + response.headers["Cache-Control"] = werkzeug.http.dump_header(cache_control) return response