avoid recursion in rewrite, thanks Jonathan
This commit is contained in:
1 parent
08f813d670
commit
1509559e78
2 files changed
+10
-16
No files matched your search
+9
-15
@@ -244,21 +244,15 @@ def try_rewrite_on_error(http_response, request, environ, ticket=None):
|
||||
url = path_info + '?' + query_string
|
||||
message = 'You are being redirected <a href="%s">here</a>'
|
||||
return HTTP(303, message % url, Location=url), environ
|
||||
else:
|
||||
error_raising_path = environ['PATH_INFO']
|
||||
# Rewrite routes_onerror path.
|
||||
path_info = '/' + path_info.lstrip(
|
||||
'/') # add leading '/' if missing
|
||||
environ['PATH_INFO'] = path_info
|
||||
error_handling_path = \
|
||||
url_in(request, environ)[2]['PATH_INFO']
|
||||
# Avoid infinite loop.
|
||||
if error_handling_path != error_raising_path:
|
||||
# wsgibase will be called recursively with the routes_onerror path.
|
||||
environ['PATH_INFO'] = path_info
|
||||
environ['QUERY_STRING'] = query_string
|
||||
environ['WEB2PY_STATUS_CODE'] = status
|
||||
return None, environ
|
||||
elif not environ.get('__ROUTES_ONERROR__', False):
|
||||
# wsgibase will be called recursively with
|
||||
# the routes_onerror path.
|
||||
environ['__ROUTES_ONERROR__'] = True # limit recursion
|
||||
path_info = '/' + path_info.lstrip('/')
|
||||
environ['PATH_INFO'] = path_info
|
||||
environ['QUERY_STRING'] = query_string
|
||||
environ['WEB2PY_STATUS_CODE'] = status
|
||||
return None, environ
|
||||
# do nothing!
|
||||
return http_response, environ
|
||||
|
||||
|
||||
Reference in new issue
Block a user