[FIX] base, website: fix routing redirect

Redirect_type was renamed from 3xx to redirect_3xx, but name is used as http
status code. It is better a redirect(301) instead of redirect(redirect_301)

Re-add the bind_to_environ, it was removed because it seems not useful, but
once you are behind a proxy, werkzeug need the environ to find the correct
hostname and more ... Transformed relative url into absolute by werkzeug was
wrong.

closes odoo/odoo#37733

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2019-10-01 15:53:04 +00:00
parent 0467cab225
commit eded0294ab
3 changed files with 11 additions and 15 deletions
+4 -4
View File
@@ -90,7 +90,7 @@ class Http(models.AbstractModel):
def _generate_routing_rules(cls, modules, converters):
website_id = request.website_routing
logger.debug("_generate_routing_rules for website: %s", website_id)
domain = [('redirect_type', 'in', ('rewrite', 'not_found')), '|', ('website_id', '=', False), ('website_id', '=', website_id)]
domain = [('redirect_type', 'in', ('308', '404')), '|', ('website_id', '=', False), ('website_id', '=', website_id)]
rewrites = dict([(x.url_from, x) for x in request.env['website.rewrite'].sudo().search(domain)])
cls._rewrite_len[website_id] = len(rewrites)
@@ -100,7 +100,7 @@ class Http(models.AbstractModel):
if url in rewrites:
rewrite = rewrites[url]
url_to = rewrite.url_to
if rewrite.redirect_type == 'rewrite':
if rewrite.redirect_type == '308':
logger.debug('Add rule %s for %s' % (url_to, website_id))
yield url_to, endpoint, routing # yield new url
@@ -109,7 +109,7 @@ class Http(models.AbstractModel):
_slug_matching = partial(cls._slug_matching, endpoint=endpoint)
routing['redirect_to'] = _slug_matching
yield url, endpoint, routing # yield original redirected to new url
elif rewrite.redirect_type == 'not_found':
elif rewrite.redirect_type == '404':
logger.debug('Return 404 for %s for website %s' % (url, website_id))
continue
else:
@@ -245,7 +245,7 @@ class Http(models.AbstractModel):
def _serve_redirect(cls):
req_page = request.httprequest.path
domain = [
('redirect_type', 'in', ('redirect_301', 'redirect_302')),
('redirect_type', 'in', ('301', '302')),
('url_from', '=', req_page)
]
domain += request.website.website_domain()
+6 -6
View File
@@ -54,11 +54,11 @@ class WebsiteRewrite(models.Model):
route_id = fields.Many2one('website.route')
url_to = fields.Char("URL to")
redirect_type = fields.Selection([
('not_found', '404 Not Found'),
('redirect_301', '301 Moved permanently'),
('redirect_302', '302 Moved temporarily'),
('rewrite', '308 Redirect / Rewrite'),
], string='Action', default="redirect_302",
('404', '404 Not Found'),
('301', '301 Moved permanently'),
('302', '302 Moved temporarily'),
('308', '308 Redirect / Rewrite'),
], string='Action', default="302",
help='''Type of redirect/Rewrite:\n
301 Moved permanently: The browser will keep in cache the new url.
302 Moved temporarily: The browser will not keep in cache the new url and ask again the next time the new url.
@@ -76,7 +76,7 @@ class WebsiteRewrite(models.Model):
def name_get(self):
result = []
for rewrite in self:
name = rewrite.redirect_type + ' - ' + rewrite.name
name = "%s - %s" % (rewrite.redirect_type, rewrite.name)
result.append((rewrite.id, name))
return result
+1 -5
View File
@@ -88,11 +88,7 @@ class IrHttp(models.AbstractModel):
@classmethod
def _match(cls, path_info, key=None):
return cls.routing_map(key=key).bind('').match(
return_rule=True,
method=request.httprequest.method,
path_info=path_info
)
return cls.routing_map().bind_to_environ(request.httprequest.environ).match(path_info=path_info, return_rule=True)
@classmethod
def _auth_method_user(cls):