[FIX] base: fixes http redirection

The 7d85ab1eac 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
This commit is contained in:
Thanh Dodeur
2019-02-04 10:16:12 +00:00
parent 240df8225c
commit a86b726a27
3 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -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'))
+2 -1
View File
@@ -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)
+2 -2
View File
@@ -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: