From b11b6bc902daeb354a5afafd801a6835eff81982 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Fri, 19 Apr 2019 13:46:28 +0000 Subject: [PATCH] [IMP] base: change cache busting middleware In the HTTP pipeline, there is a middleware called DisableCacheMiddleware that is called on every request to check if we are in debug mode, to remove the cache headers and replace them with a static 'no-cache' so the browser has to contact the server and check for a new version of every ressouce. There were 2 problems with it: 1. it was doing more work than strictly needed when not in debug, like rebuilding a list of headers for every request 2. it was removing Etag (case sensitive) with a typo and other headers that could have been left in place. This commit fixes those 2 issues by only modifying the headers if we are in debug mode, and only removing the header 'cache-control' and replacing it with 'cache-control: no-cache' --- odoo/http.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/odoo/http.py b/odoo/http.py index 750c0b3c0d5..67243cf5a52 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -1248,17 +1248,16 @@ class DisableCacheMiddleware(object): parsed = urls.url_parse(referer) debug = parsed.query.count('debug') >= 1 - new_headers = [] - unwanted_keys = ['Last-Modified'] if debug: new_headers = [('Cache-Control', 'no-cache')] - unwanted_keys += ['Expires', 'Etag', 'Cache-Control'] - for k, v in headers: - if k not in unwanted_keys: - new_headers.append((k, v)) + for k, v in headers: + if k.lower() != 'cache-control': + new_headers.append((k, v)) - start_response(status, new_headers) + start_response(status, new_headers) + else: + start_response(status, headers) return self.app(environ, start_wrapped) class Root(object):