comparison src/server/server.py @ 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 f2170536ba23
comparison
equal deleted inserted replaced
1046:614843c49d6c 1047:3f6f4d907c30
350 resource = super(LiberviaRootResource, self).getChild(name, request) 350 resource = super(LiberviaRootResource, self).getChild(name, request)
351 351
352 if isinstance(resource, web_resource.NoResource): 352 if isinstance(resource, web_resource.NoResource):
353 # if nothing was found, we try our luck with redirections 353 # if nothing was found, we try our luck with redirections
354 # XXX: we want redirections to happen only if everything else failed 354 # XXX: we want redirections to happen only if everything else failed
355 355 path_elt = request.prepath + request.postpath
356 # first we check with current URL 356 for idx in xrange(len(path_elt), 0, -1):
357 # there our last try with the remaining URL 357 test_url = '/'.join(path_elt[:idx]).lower()
358 for path_elts in (request.prepath, 358 if test_url in self.redirections:
359 [name] + request.postpath): 359 request_data = self.redirections[test_url]
360 current_url = '/'.join(path_elts).lower() 360 request.postpath = path_elt[idx:]
361 try:
362 request_data = self.redirections[current_url]
363 except KeyError:
364 # no redirection for this url
365 pass
366 else:
367 return self._redirect(request, request_data) 361 return self._redirect(request, request_data)
368 362
369 return resource 363 return resource
370 364
371 def createSimilarFile(self, path): 365 def createSimilarFile(self, path):