summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2019-04-26 10:55:32 +0000
committerSébastien Theys <seb@odoo.com>2019-04-29 13:45:34 +0000
commit7d3fe51100302f2c1af00a343c17940e530b4dbf (patch)
treefa0d7650e503394b1627ec2124bb80385ee4daf3 /addons
parent09ff05ba45d08f980f1b55c23b24420f78e9a943 (diff)
[FIX] http,web,website_*: return the correct Content-Type for images
* = website_profile, website_slides Before this commit, the returned Content-Type was not always correct, for example if the image tool was changing the format, which happens when given a BMP (converted to PNG), or other types being converted to JPEG. The previous method `force_contenttype` was too specific and it wasn't available in every controller. It didn't even need to be a controller method because it didn't use self. Now we create a generic helper to ease updating headers. The Content-Type is only updated when it is safe to do. It is especially unsafe for example for SVG files. task-1958000 PR: #31811
Diffstat (limited to 'addons')
-rw-r--r--addons/web/controllers/main.py8
-rw-r--r--addons/website_profile/controllers/main.py2
-rw-r--r--addons/website_slides/controllers/main.py2
3 files changed, 3 insertions, 9 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index ecb38a3dd6f..a14a02ebb9b 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -971,11 +971,6 @@ class Binary(http.Controller):
addons_path = http.addons_manifest['web']['addons_path']
return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', image), 'rb').read()
- def force_contenttype(self, headers, contenttype='image/png'):
- dictheaders = dict(headers)
- dictheaders['Content-Type'] = contenttype
- return list(dictheaders.items())
-
@http.route(['/web/content',
'/web/content/<string:xmlid>',
'/web/content/<string:xmlid>/<string:filename>',
@@ -1034,14 +1029,13 @@ class Binary(http.Controller):
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if not image_base64:
image_base64 = base64.b64encode(self.placeholder(image=placeholder))
- headers = self.force_contenttype(headers, contenttype='image/png')
if not (width or height):
width, height = odoo.tools.image_guess_size_from_field_name(field)
image_base64 = image_process(image_base64, (width, height), crop=crop)
content = base64.b64decode(image_base64)
- headers.append(('Content-Length', len(content)))
+ headers = http.set_safe_image_headers(headers, content)
response = request.make_response(content, headers)
response.status_code = status
return response
diff --git a/addons/website_profile/controllers/main.py b/addons/website_profile/controllers/main.py
index 3b5bc7843bc..5d379643e5d 100644
--- a/addons/website_profile/controllers/main.py
+++ b/addons/website_profile/controllers/main.py
@@ -98,7 +98,7 @@ class WebsiteProfile(http.Controller):
image_base64 = tools.image_process(image_base64, (width, height), crop=crop)
content = base64.b64decode(image_base64)
- headers.append(('Content-Length', len(content)))
+ headers = http.set_safe_image_headers(headers, content)
response = request.make_response(content, headers)
response.status_code = status
return response
diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py
index 754edf27960..4da2d91f6a7 100644
--- a/addons/website_slides/controllers/main.py
+++ b/addons/website_slides/controllers/main.py
@@ -531,7 +531,7 @@ class WebsiteSlides(WebsiteProfile):
image_base64 = tools.image_process(image_base64, (width, height), crop=crop)
content = base64.b64decode(image_base64)
- headers.append(('Content-Length', len(content)))
+ headers = http.set_safe_image_headers(headers, content)
response = request.make_response(content, headers)
response.status_code = status
return response