From a86b726a27ed68debecdda982ba7b1fff34d7243 Mon Sep 17 00:00:00 2001 From: Thanh Dodeur Date: Fri, 1 Feb 2019 22:23:29 +0000 Subject: [PATCH] [FIX] base: fixes http redirection The 7d85ab1eac6dbf33d56c6a1f8bf7e9e12bb8008e refactor of 'ir.http' introduced changes in `web/image` that caused the route to no longer return early (to avoid data processing steps) in the case of redirection and that caused `binary_content` to not set the mimetype of the `ir.attachment` when it was an URL. This commit fixes those issues, allowing `web/image` to redirect properly. closes odoo/odoo#30777 --- addons/web/controllers/main.py | 2 +- odoo/addons/base/models/ir_http.py | 3 ++- odoo/tools/image.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 3eaed012f25..2c79fed7e4c 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1061,7 +1061,7 @@ class Binary(http.Controller): filename_field=filename_field, download=download, mimetype=mimetype, default_mimetype='image/png', access_token=access_token) - if status != 200 and download: + if status == 301 or (status != 200 and download): return request.env['ir.http']._response_by_status(status, headers, content) if not content: content = base64.b64encode(self.placeholder(image='placeholder.png')) diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index 1cc910b58f9..293269d61d1 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -277,7 +277,8 @@ class IrHttp(models.AbstractModel): @classmethod def _binary_ir_attachment_redirect_content(cls, record, default_mimetype='application/octet-stream'): # mainly used for theme images attachemnts - status = content = filename = mimetype = filehash = None + status = content = filename = filehash = None + mimetype = getattr(record, 'mimetype', False) if record.type == 'url' and record.url: # if url in in the form /somehint server locally url_match = re.match("^/(\w+)/(.+)$", record.url) diff --git a/odoo/tools/image.py b/odoo/tools/image.py index 1cec35b8c23..ce423cb2a1e 100644 --- a/odoo/tools/image.py +++ b/odoo/tools/image.py @@ -321,11 +321,11 @@ def limited_image_resize(content, width=None, height=None, crop=False, upper_lim """ :param content: bytes (should be an image) """ - if content: + if content and (width or height): signatures = [b'\xFF\xD8\xFF', b'\x89PNG\r\n\x1A\n'] decoded_content = base64.b64decode(content) is_image = any(decoded_content.startswith(signature) for signature in signatures) - if (width or height) and is_image: + if is_image: height = int(height or 0) width = int(width or 0) if crop: