[FIX] base: skip etag when attachment checksum is missing
png images not shown on ir.attachment kanban Attachment that use db_datas have no checksum by default, which is used to compute the stream's http ETag. Skip updating the ETag when it is missing and determine freshness using the Last-Modified header instead. closes odoo/odoo#139498 X-original-commit: 2d43bbae72fddf17e7d9045e90dbc070b2f57a19 Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
This commit is contained in:
committed by
Julien Castiaux
parent
0c68ddce1e
commit
b0b1dc5e0f
@@ -220,13 +220,14 @@ class IrBinary(models.AbstractModel):
|
||||
|
||||
if (width, height) == (0, 0):
|
||||
width, height = image_guess_size_from_field_name(field_name)
|
||||
stream.etag += f'-{width}x{height}-crop={crop}-quality={quality}'
|
||||
|
||||
if isinstance(stream.etag, str):
|
||||
stream.etag += f'-{width}x{height}-crop={crop}-quality={quality}'
|
||||
if isinstance(stream.last_modified, (int, float)):
|
||||
stream.last_modified = datetime.utcfromtimestamp(stream.last_modified)
|
||||
modified = werkzeug.http.is_resource_modified(
|
||||
request.httprequest.environ,
|
||||
etag=stream.etag,
|
||||
etag=stream.etag if isinstance(stream.etag, str) else None,
|
||||
last_modified=stream.last_modified
|
||||
)
|
||||
|
||||
|
||||
@@ -280,6 +280,37 @@ class TestHttpStatic(TestHttpStaticCommon):
|
||||
res = self.url_open('/web/content/test_http.earth?field=galaxy_picture')
|
||||
self.assertEqual(res.status_code, 404)
|
||||
|
||||
def test_static17_content_missing_checksum(self):
|
||||
att = self.env['ir.attachment'].create({
|
||||
'name': 'testhttp.txt',
|
||||
'db_datas': 'some data',
|
||||
'public': True,
|
||||
})
|
||||
self.assertFalse(att.checksum)
|
||||
self.assertDownload(
|
||||
url=f'/web/content/{att.id}',
|
||||
headers={},
|
||||
|
||||
assert_status_code=200,
|
||||
assert_headers={
|
||||
'Content-Length': '9',
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
'Content-Disposition': 'inline; filename=testhttp.txt',
|
||||
},
|
||||
assert_content=b'some data',
|
||||
)
|
||||
|
||||
def test_static18_image_missing_checksum(self):
|
||||
with file_open('test_http/static/src/img/gizeh.png', 'rb') as file:
|
||||
att = self.env['ir.attachment'].create({
|
||||
'name': 'gizeh.png',
|
||||
'db_datas': file.read(),
|
||||
'mimetype': 'image/png',
|
||||
'public': True,
|
||||
})
|
||||
self.assertFalse(att.checksum)
|
||||
self.assertDownloadGizeh(f'/web/image/{att.id}')
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestHttpStaticLogo(TestHttpStaticCommon):
|
||||
|
||||
Reference in New Issue
Block a user