changeset 1047:3f6f4d907c30

server: better redirection (fixed issue in remaining path arguments)
author Goffi <goffi@goffi.org>
date Wed, 24 Jan 2018 21:46:09 +0100
parents 614843c49d6c
children d4290178662c
files src/server/server.py
diffstat 1 files changed, 6 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/server.py	Wed Jan 24 21:44:26 2018 +0100
+++ b/src/server/server.py	Wed Jan 24 21:46:09 2018 +0100
@@ -352,18 +352,12 @@
         if isinstance(resource, web_resource.NoResource):
             # if nothing was found, we try our luck with redirections
             # XXX: we want redirections to happen only if everything else failed
-
-            # first we check with current URL
-            # there our last try with the remaining URL
-            for path_elts in (request.prepath,
-                         [name] + request.postpath):
-                current_url = '/'.join(path_elts).lower()
-                try:
-                    request_data = self.redirections[current_url]
-                except KeyError:
-                    # no redirection for this url
-                    pass
-                else:
+            path_elt = request.prepath + request.postpath
+            for idx in xrange(len(path_elt), 0, -1):
+                test_url = '/'.join(path_elt[:idx]).lower()
+                if test_url in self.redirections:
+                    request_data = self.redirections[test_url]
+                    request.postpath = path_elt[idx:]
                     return self._redirect(request, request_data)
 
         return resource