From c2cbb75319dfde57420bf38f8f057ad2f55cfcec Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 17 Aug 2015 16:05:15 +0200 Subject: [PATCH] [FIX] web: _serve_attachment should not trigger redirect loops When the Bundle mechanism caches bundle files into the ir.attachment table, it can sometimes cache an empty resource file (For example, if a less/saas compiled file results in an empty CSS file) for the bundle URL. The appropriate behavior for _serve_attachment() when the browser loads that bundle URL is to return an empty file (which is the correct content), instead of redirecting again to the same URL, triggering a loop. In addition, this commit removes the special case for returning 204 No Content. This HTTP status code is not really meant for GET requests - returning an empty file with a 304 or 200 code is more appropriate and allows for normal browser caching. --- openerp/addons/base/ir/ir_http.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index 5320a0c0b95..c8bf0776d01 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -109,11 +109,9 @@ class ir_http(osv.AbstractModel): datas = attach[0]['datas'] or '' name = attach[0]['name'] - if not datas: - if name.startswith(('http://', 'https://', '/')): - return werkzeug.utils.redirect(name, 301) - else: - return werkzeug.wrappers.Response(status=204) # NO CONTENT + if (not datas and name != request.httprequest.path and + name.startswith(('http://', 'https://', '/'))): + return werkzeug.utils.redirect(name, 301) response = werkzeug.wrappers.Response() server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT