From eab7467efaf94a782ed927f937af6be613b6e3c1 Mon Sep 17 00:00:00 2001 From: Parthiv Patel Date: Wed, 28 Feb 2024 08:35:08 +0000 Subject: [PATCH] [PATCH] Upstream patch - 28022024 --- addons/http_routing/models/ir_http.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 24f73d05d1..ef650ab825 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -19,7 +19,7 @@ import flectra from flectra import api, models, registry, exceptions, tools, http from flectra.addons.base.models.ir_http import RequestUID, ModelConverter from flectra.addons.base.models.qweb import QWebException -from flectra.http import request +from flectra.http import request, HTTPRequest from flectra.osv import expression from flectra.tools import config, ustr, pycompat @@ -519,6 +519,10 @@ class IrHttp(models.AbstractModel): @classmethod def reroute(cls, path): + if isinstance(path, str): + path = path.encode("utf-8") + path = path.decode("latin1", "replace") + if not hasattr(request, 'rerouting'): request.rerouting = [request.httprequest.path] if path in request.rerouting: @@ -526,16 +530,8 @@ class IrHttp(models.AbstractModel): request.rerouting.append(path) if len(request.rerouting) > cls.rerouting_limit: raise Exception("Rerouting limit exceeded") - request.httprequest.environ['PATH_INFO'] = path - # void werkzeug cached_property. TODO: find a proper way to do this - for key in ('full_path', 'url', 'base_url'): - request.httprequest.__dict__.pop(key, None) - # since werkzeug 2.0 `path`` became an attribute and is not a cached property anymore - if hasattr(type(request.httprequest), 'path'): # cached property - request.httprequest.__dict__.pop('path', None) - else: # direct attribute - request.httprequest.path = '/' + path.lstrip('/') - + environ = dict(request.httprequest._HTTPRequest__environ, PATH_INFO=path) + request.httprequest = HTTPRequest(environ) return cls._dispatch() @classmethod @@ -577,7 +573,7 @@ class IrHttp(models.AbstractModel): elif isinstance(exception, QWebException): values.update(qweb_exception=exception) - if type(exception.error) == exceptions.AccessError: + if isinstance(exception.error, exceptions.AccessError): code = 403 elif isinstance(exception, werkzeug.exceptions.HTTPException):