Last active
September 9, 2015 14:59
-
-
Save jan-matejka/ffda5e14e3840d03408f to your computer and use it in GitHub Desktop.
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
| curl localhost:8080 -d @json |
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
| #!/usr/bin/python3 | |
| import asyncio | |
| import aiohttp | |
| from aiohttp import web | |
| def process_body(f): | |
| try: | |
| print(f.result()) | |
| except aiohttp.errors.ClientDisconnectedError: | |
| print("disconnected") | |
| def sink(r): | |
| asyncio.Task(r.json()).add_done_callback(process_body) | |
| return web.Response() | |
| def listen( | |
| loop | |
| , ip : str | |
| , port : int | |
| ) -> None: | |
| app = web.Application(loop = loop) | |
| app.router.add_route( | |
| 'POST' | |
| , '/' | |
| , sink | |
| ) | |
| srv = loop.run_until_complete(loop.create_server(app.make_handler(), ip, port)) | |
| print("Server started at {0}".format(srv.sockets[0].getsockname())) | |
| def main(): # pragma: no cover | |
| loop = asyncio.get_event_loop() | |
| listen(loop, '0.0.0.0', 8080) | |
| loop.run_forever() | |
| main() |
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
| resp=$(./request.sh) | |
| sent=$(cat json) | |
| [[ "${resp}" == "${sent}" ]] && exit 0 || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment