[IMP] move all the making-stuff-conditional-based-on-other-stuff code to a dedicated method of the WebClient controller
provides a single point of configuration if/when we decide to change the cache-control stuff, mostly bzr revid: xmo@openerp.com-20120210141338-3aib9ls3b72gr4ez
This commit is contained in:
parent
10f215ef35
commit
3b565386c2
|
@ -166,6 +166,30 @@ class WebClient(openerpweb.Controller):
|
||||||
return max(datetime.datetime.fromtimestamp(os.path.getmtime(f))
|
return max(datetime.datetime.fromtimestamp(os.path.getmtime(f))
|
||||||
for f in files)
|
for f in files)
|
||||||
|
|
||||||
|
def make_conditional(self, req, response, last_modified=None, etag=None):
|
||||||
|
""" Makes the provided response conditional based upon the request,
|
||||||
|
and mandates revalidation from clients
|
||||||
|
|
||||||
|
Uses Werkzeug's own :meth:`ETagResponseMixin.make_conditional`, after
|
||||||
|
setting ``last_modified`` and ``etag`` correctly on the response object
|
||||||
|
|
||||||
|
:param req: OpenERP request
|
||||||
|
:type req: web.common.http.WebRequest
|
||||||
|
:param response: Werkzeug response
|
||||||
|
:type response: werkzeug.wrappers.Response
|
||||||
|
:param datetime.datetime last_modified: last modification date of the response content
|
||||||
|
:param str etag: some sort of checksum of the content (deep etag)
|
||||||
|
:return: the response object provided
|
||||||
|
:rtype: werkzeug.wrappers.Response
|
||||||
|
"""
|
||||||
|
response.cache_control.must_revalidate = True
|
||||||
|
response.cache_control.max_age = 0
|
||||||
|
if last_modified:
|
||||||
|
response.last_modified = last_modified
|
||||||
|
if etag:
|
||||||
|
response.set_etag(etag)
|
||||||
|
return response.make_conditional(req.httprequest)
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def css(self, req, mods=None):
|
def css(self, req, mods=None):
|
||||||
files = list(self.manifest_glob(req, mods, 'css'))
|
files = list(self.manifest_glob(req, mods, 'css'))
|
||||||
|
@ -202,15 +226,10 @@ class WebClient(openerpweb.Controller):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
content, checksum = concat_files((f[0] for f in files), reader)
|
content, checksum = concat_files((f[0] for f in files), reader)
|
||||||
if req.httprequest.if_none_match and checksum in req.httprequest.if_none_match:
|
|
||||||
return werkzeug.wrappers.Response(status=304)
|
|
||||||
|
|
||||||
response = req.make_response(content, [('Content-Type', 'text/css')])
|
return self.make_conditional(
|
||||||
response.cache_control.must_revalidate = True
|
req, req.make_response(content, [('Content-Type', 'text/css')]),
|
||||||
response.cache_control.max_age = 0
|
last_modified, checksum)
|
||||||
response.last_modified = last_modified
|
|
||||||
response.set_etag(checksum)
|
|
||||||
return response
|
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def js(self, req, mods=None):
|
def js(self, req, mods=None):
|
||||||
|
@ -222,15 +241,10 @@ class WebClient(openerpweb.Controller):
|
||||||
return werkzeug.wrappers.Response(status=304)
|
return werkzeug.wrappers.Response(status=304)
|
||||||
|
|
||||||
content, checksum = concat_files(files, intersperse=';')
|
content, checksum = concat_files(files, intersperse=';')
|
||||||
if req.httprequest.if_none_match and checksum in req.httprequest.if_none_match:
|
|
||||||
return werkzeug.wrappers.Response(status=304)
|
|
||||||
|
|
||||||
resp = req.make_response(content, [('Content-Type', 'application/javascript')])
|
return self.make_conditional(
|
||||||
resp.cache_control.must_revalidate = True
|
req, req.make_response(content, [('Content-Type', 'application/javascript')]),
|
||||||
resp.cache_control.max_age = 0
|
last_modified, checksum)
|
||||||
resp.last_modified = last_modified
|
|
||||||
resp.set_etag(checksum)
|
|
||||||
return resp
|
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def qweb(self, req, mods=None):
|
def qweb(self, req, mods=None):
|
||||||
|
@ -240,16 +254,10 @@ class WebClient(openerpweb.Controller):
|
||||||
return werkzeug.wrappers.Response(status=304)
|
return werkzeug.wrappers.Response(status=304)
|
||||||
|
|
||||||
content,checksum = concat_xml(files)
|
content,checksum = concat_xml(files)
|
||||||
if req.httprequest.if_none_match and checksum in req.httprequest.if_none_match:
|
|
||||||
return werkzeug.wrappers.Response(status=304)
|
|
||||||
|
|
||||||
response = req.make_response(content, [('Content-Type', 'text/xml')])
|
|
||||||
response.cache_control.must_revalidate = True
|
|
||||||
response.cache_control.max_age = 0
|
|
||||||
response.last_modified = last_modified
|
|
||||||
response.set_etag(checksum)
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
return self.make_conditional(
|
||||||
|
req, req.make_response(content, [('Content-Type', 'text/xml')]),
|
||||||
|
last_modified, checksum)
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def home(self, req, s_action=None, **kw):
|
def home(self, req, s_action=None, **kw):
|
||||||
|
|
Loading…
Reference in New Issue