Code Repositories xandikos / aiohttp
Sanitize path handler. Jelmer Vernooń≥ 4 months ago
2 changed file(s) with 13 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
830830
831831 def get_resource(self, relpath):
832832 relpath = posixpath.normpath(relpath)
833 if not relpath.startswith('/'):
834 raise ValueError('relpath %r should start with /')
833835 if relpath == '/':
834836 return RootPage(self)
835837 p = self._map_to_file_path(relpath)
10841086 'Run xandikos with --autocreate?',
10851087 options.current_user_principal)
10861088
1087 app = XandikosApp(
1089 main_app = XandikosApp(
10881090 backend,
10891091 current_user_principal=options.current_user_principal)
1090 xandikos_handler = app.aiohttp_handler
1092 async def xandikos_handler(request):
1093 return await main_app.aiohttp_handler(request, options.route_prefix)
10911094
10921095 logging.info('Listening on %s:%s', options.listen_address,
10931096 options.port)
11051108 async def redirect_to_subprefix(request):
11061109 return web.HTTPFound(options.route_prefix)
11071110 app.router.add_route("*", "/", redirect_to_subprefix)
1108 app.add_subapp(options.route_prefix, xandikos_app)
1111 r = app.add_subapp(options.route_prefix, xandikos_app)
11091112 else:
11101113 app.router.add_route("*", "/{path_info:.*}", xandikos_handler)
11111114 web.run_app(app, port=options.port, host=options.listen_address)
18041804 ])
18051805
18061806 def _get_resource_from_environ(self, request, environ):
1807 r = self.backend.get_resource(request.match_info['path_info'])
1808 return (request.path, request.match_info['path_info'], r)
1807 path_info = request.match_info['path_info']
1808 if not path_info.startswith('/'):
1809 path_info = '/' + path_info
1810 r = self.backend.get_resource(path_info)
1811 return (request.path, path_info, r)
18091812
18101813 def register_properties(self, properties):
18111814 for p in properties:
18701873 response = loop.run_until_complete(self._handle_request(request, environ))
18711874 return response.for_wsgi(start_response)
18721875
1873 async def aiohttp_handler(self, request):
1874 environ = {'SCRIPT_NAME': ''}
1876 async def aiohttp_handler(self, request, route_prefix='/'):
1877 environ = {'SCRIPT_NAME': route_prefix}
18751878 response = await self._handle_request(request, environ)
18761879 return response.for_aiohttp()
18771880