Last active
January 13, 2019 18:26
-
-
Save rhwlo/5ff3cb6bae8deb6abb4a1e527ad9583e to your computer and use it in GitHub Desktop.
example server and client to reproduce a Reason-Phrase bug in Python’s aiohttp library (https://github.com/aio-libs/aiohttp/issues/3532)
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 urllib.parse import urljoin | |
from aiohttp.client import request | |
async def main(): | |
for endpoint in ["/success_without_reason", "/failure_without_reason"]: | |
async with request("get", urljoin("http://0.0.0.0:8080", | |
endpoint)) as resp: | |
resp.raise_for_status() | |
print(f"{endpoint} passes ok") | |
asyncio.get_event_loop().run_until_complete(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
from aiohttp import web | |
async def success_without_reason(request): | |
return web.Response(body="everything is ok", status=200, reason="") | |
async def failure_without_reason(request): | |
return web.Response(body="my tummy feels funny", status=500, reason="") | |
def init(): | |
app = web.Application() | |
app.router.add_get("/success_without_reason", success_without_reason) | |
app.router.add_get("/failure_without_reason", failure_without_reason) | |
return app | |
web.run_app(init()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment