diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-04-19 13:46:28 +0000 |
|---|---|---|
| committer | Vincent Schippefilt <vsc@odoo.com> | 2019-05-22 07:52:07 +0000 |
| commit | b11b6bc902daeb354a5afafd801a6835eff81982 (patch) | |
| tree | c5d513dd1812962a61398aa87f96a91e7e93889f /odoo/http.py | |
| parent | 8a28cc22fd242f5fb59f23d1443ed8ed438249d7 (diff) | |
[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'
Diffstat (limited to 'odoo/http.py')
| -rw-r--r-- | odoo/http.py | 13 |
1 files 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): |
