This commit is contained in:
yumoqing 2024-12-20 15:18:39 +08:00
parent 08e40a7692
commit 0023e2eeca

View File

@ -52,7 +52,6 @@ async def stream_response(request, async_data_generator, content_type='text/html
res = StreamResponse() res = StreamResponse()
if content_type: if content_type:
res.content_type = content_type res.content_type = content_type
res.set_status(200)
await res.prepare(request) await res.prepare(request)
async for d in async_data_generator(): async for d in async_data_generator():
if isinstance(d, bytes): if isinstance(d, bytes):
@ -62,6 +61,7 @@ async def stream_response(request, async_data_generator, content_type='text/html
else: else:
d = json.dumps(d) d = json.dumps(d)
await res.write(d.encode('utf-8')) await res.write(d.encode('utf-8'))
await res.drain()
await res.write_eof() await res.write_eof()
return res return res