avoid recursion in rewrite, thanks Jonathan

This commit is contained in:
mdipierro
2013-06-21 01:47:34 -05:00
parent 08f813d670
commit 1509559e78
2 changed files with 10 additions and 16 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.5.1-stable+timestamp.2013.06.20.16.43.32
Version 2.5.1-stable+timestamp.2013.06.21.01.46.48
+9 -15
View File
@@ -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