Expose new path used to compute new url in RequestRedirect #3000
Open
Description
The RequestRedirect exception is raised with new_url set to
the computed URL that should be redirected to, but we don't
expose the path that was used to compute the URL in the exception
so depending code needs to urlparse() the URL even though
werkzeug already has the path and can pass it along in the exception.
Referring to this example code:
def resolve_endpoint(self, environ, path, method):
"""Resolve endpoint from the url map.
:environ Environment: The environment.
:path str: The request path.
:method str: The request method.
:returns str: The endpoint from the url map.
"""
urls = url_map.bind_to_environ(environ)
try:
endpoint, _ = urls.match(path, method=method)
return endpoint
except routing.RequestRedirect as e:
r = urlparse(e.new_url)
return resolve_endpoint(environ, r.path, method)
# FIXME: this could be e.new_path if RequestRedirect passed path
# return resolve_endpoint(environ, e.new_path, method)
except (wexc.NotFound, wexc.MethodNotAllowed):
pass
return None
Metadata
Assignees
Labels
No labels