[FIX] base: adapt _serve_attachment for saas-6

Commit c2cbb75319 modified
the logic of _serve_attachment for empty files. After this
patch, empty files are returned with status 200 and a valid
ETag, for proper browser caching.
However the new stored `checksum` field in saas-6 was not
being computed for empty files, resulting in errors when
those files were being served.
This commit updates the logic to restore the caching
behavior for empty files after the forward-port to saas-6.
This commit is contained in:
Olivier Dony
2015-08-25 18:10:11 +02:00
parent e16d495d89
commit 60de771979
2 changed files with 4 additions and 4 deletions
+2 -3
View File
@@ -255,9 +255,8 @@ class ir_attachment(osv.osv):
""" compute the checksum for the given datas
:param bin_data : datas in its binary form
"""
if bin_data:
return hashlib.sha1(bin_data).hexdigest()
return False
# an empty file has a checksum too (for caching)
return hashlib.sha1(bin_data or '').hexdigest()
def _compute_mimetype(self, values):
""" compute the mimetype of the given values
+2 -1
View File
@@ -107,6 +107,7 @@ class ir_http(osv.AbstractModel):
wdate = attach[0]['__last_update']
datas = attach[0]['datas'] or ''
name = attach[0]['name']
checksum = attach[0]['checksum'] or hashlib.sha1(datas).hexdigest()
if (not datas and name != request.httprequest.path and
name.startswith(('http://', 'https://', '/'))):
@@ -120,7 +121,7 @@ class ir_http(osv.AbstractModel):
# just in case we have a timestamp without microseconds
response.last_modified = datetime.datetime.strptime(wdate, server_format)
response.set_etag(attach[0]['checksum'])
response.set_etag(checksum)
response.make_conditional(request.httprequest)
if response.status_code == 304: