From e0aafd1c5ebffe791fddf07c01b71b1cc52cd24a Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 18 Jul 2012 16:22:35 +0200 Subject: [PATCH] [FIX] Disable cache middleware for debug mode bzr revid: al@openerp.com-20120718142235-x4uwzsar7ak6sxgk --- addons/web/common/http.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/web/common/http.py b/addons/web/common/http.py index cc76a554693..7b73c2169ea 100644 --- a/addons/web/common/http.py +++ b/addons/web/common/http.py @@ -417,6 +417,20 @@ class ControllerType(type): class Controller(object): __metaclass__ = ControllerType +class DisableCacheMiddleware(object): + def __init__(self, app): + self.app = app + def __call__(self, environ, start_response): + def start_wrapped(status, headers): + debug = environ.get('HTTP_REFERER', '').find('debug') != -1 + filtered_headers = [(k,v) for k,v in headers if not (k=='Last-Modified' or (debug and k=='Cache-Control'))] + if debug: + filtered_headers.append(('Cache-Control', 'no-cache')) + print headers + print filtered_headers + start_response(status, filtered_headers) + return self.app(environ, start_wrapped) + class Root(object): """Root WSGI application for the OpenERP Web Client. @@ -452,8 +466,8 @@ class Root(object): static_dirs = self._load_addons(openerp_addons_namespace) if options.serve_static: - self.dispatch = werkzeug.wsgi.SharedDataMiddleware( - self.dispatch, static_dirs, cache=False) + app = werkzeug.wsgi.SharedDataMiddleware( self.dispatch, static_dirs) + self.dispatch = DisableCacheMiddleware(app) if options.session_storage: if not os.path.exists(options.session_storage):