Reborn (@RebornQ)关于 Python 流式返回处理的提问 中发帖

代码
http_client: httpx.AsyncClient
# ...

# 发起上游请求
try:
resp = await http_client.request(
method=request.method,
url=target_url,
headers=forward_headers,
content=body,
)
except httpx.RequestError as e:
return Response(content=f"Upstream request failed: {e}", status_code=502)

async def iter_response():
async for chunk in resp.aiter_bytes():
yi...