Streaming request by async for.

This commit is contained in:
L. Kärkkäinen 2020-02-21 10:51:58 +02:00
parent 91f6abaa81
commit 6279eac3d1

View File

@ -56,6 +56,13 @@ class StreamBuffer:
self._queue.task_done()
return payload
async def __aiter__(self):
while True:
data = await self.read()
if not data:
return
yield data
async def put(self, payload):
await self._queue.put(payload)
@ -161,6 +168,10 @@ class Request:
def body_finish(self):
self.body = b"".join(self.body)
async def receive_body(self):
assert self.body == []
self.body = b"".join([data async for data in self.stream])
@property
def json(self):
if self.parsed_json is None: