Faster HTTP streaming when using ASGI (#318)
This commit is contained in:
@@ -127,19 +127,17 @@ class Microdot(BaseMicrodot):
|
||||
monitor_task = asyncio.ensure_future(cancel_monitor())
|
||||
|
||||
body_iter = res.body_iter().__aiter__()
|
||||
res_body = b''
|
||||
try:
|
||||
res_body = await body_iter.__anext__()
|
||||
while not cancelled: # pragma: no branch
|
||||
next_body = await body_iter.__anext__()
|
||||
res_body = await body_iter.__anext__()
|
||||
await send({'type': 'http.response.body',
|
||||
'body': res_body,
|
||||
'more_body': True})
|
||||
res_body = next_body
|
||||
except StopAsyncIteration:
|
||||
await send({'type': 'http.response.body',
|
||||
'body': res_body,
|
||||
'more_body': False})
|
||||
pass
|
||||
await send({'type': 'http.response.body',
|
||||
'body': b'',
|
||||
'more_body': False})
|
||||
if hasattr(body_iter, 'aclose'): # pragma: no branch
|
||||
await body_iter.aclose()
|
||||
cancelled = True
|
||||
|
||||
Reference in New Issue
Block a user