Streaming request by async for.
This commit is contained in:
parent
91f6abaa81
commit
6279eac3d1
|
@ -56,6 +56,13 @@ class StreamBuffer:
|
||||||
self._queue.task_done()
|
self._queue.task_done()
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
async def __aiter__(self):
|
||||||
|
while True:
|
||||||
|
data = await self.read()
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
yield data
|
||||||
|
|
||||||
async def put(self, payload):
|
async def put(self, payload):
|
||||||
await self._queue.put(payload)
|
await self._queue.put(payload)
|
||||||
|
|
||||||
|
@ -161,6 +168,10 @@ class Request:
|
||||||
def body_finish(self):
|
def body_finish(self):
|
||||||
self.body = b"".join(self.body)
|
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
|
@property
|
||||||
def json(self):
|
def json(self):
|
||||||
if self.parsed_json is None:
|
if self.parsed_json is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user