Skip to content

Instantly share code, notes, and snippets.

@nu774
Created August 25, 2022 04:29
Show Gist options
  • Save nu774/559ad1032de8fe6081620cf547972cdf to your computer and use it in GitHub Desktop.
Save nu774/559ad1032de8fe6081620cf547972cdf to your computer and use it in GitHub Desktop.
ASGI app that iteratively echo backs request body
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