Created
August 25, 2022 04:29
-
-
Save nu774/559ad1032de8fe6081620cf547972cdf to your computer and use it in GitHub Desktop.
ASGI app that iteratively echo backs request body
This file contains 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
async def application(scope, receive, send): | |
if scope['type'] != 'http': | |
return | |
initial = True | |
more_body = True | |
while more_body: | |
chunk = await receive() | |
if chunk['type'] != 'http.request': | |
break | |
body = chunk['body'] | |
if initial: | |
await send({'type': 'http.response.start', 'status': 200}) | |
initial = False | |
more_body = chunk['more_body'] | |
await send({'type': 'http.response.body', 'body': body, 'more_body': more_body}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment