Add stream support for bp.add_route() (#1482)

* Fix #1454

* Update doc

* Fix F632 in response.py
This commit is contained in:
Jacob
2019-02-05 21:47:46 +08:00
committed by Stephen Sadowski
parent bc7d0f0da5
commit 52bdd1d5a2
4 changed files with 35 additions and 3 deletions

View File

@@ -42,7 +42,7 @@ async def handler(request):
@bp.put('/bp_stream', stream=True)
async def bp_handler(request):
async def bp_put_handler(request):
result = ''
while True:
body = await request.stream.read()
@@ -52,6 +52,19 @@ async def bp_handler(request):
return text(result)
# You can also use `bp.add_route()` with stream argument
async def bp_post_handler(request):
result = ''
while True:
body = await request.stream.read()
if body is None:
break
result += body.decode('utf-8').replace('1', 'A')
return text(result)
bp.add_route(bp_post_handler, '/bp_stream', methods=['POST'], stream=True)
async def post_handler(request):
result = ''
while True: