Created
June 15, 2015 20:55
-
-
Save Lothiraldan/2e4b36ac55946ff0ba3b to your computer and use it in GitHub Desktop.
Handling of %2F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from aiohttp.web import Application, Response | |
@asyncio.coroutine | |
def resource(request): | |
return Response(text=repr(request.match_info)) | |
@asyncio.coroutine | |
def custom_aсtion(request): | |
return Response(text=repr(request.match_info)) | |
@asyncio.coroutine | |
def init(loop): | |
app = Application(loop=loop) | |
app.router.add_route('GET', '/{collection}/{resource_id}', resource) | |
app.router.add_route('GET', '/{collection}/{resource_id}/', resource) | |
app.router.add_route('GET', '/{collection}/{resource_id}/{custom_action}', | |
custom_aсtion) | |
handler = app.make_handler() | |
srv = yield from loop.create_server(handler, '127.0.0.1', 8080) | |
print("Server started at http://127.0.0.1:8080") | |
return srv, handler | |
loop = asyncio.get_event_loop() | |
srv, handler = loop.run_until_complete(init(loop)) | |
try: | |
loop.run_forever() | |
except KeyboardInterrupt: | |
loop.run_until_complete(handler.finish_connections()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment