We should stream the Chunks for PUT requests.

This commit is contained in:
Lutchy Horace 2025-04-02 12:50:18 -04:00
parent 3d80586e26
commit 7be4d3a0f4

View file

@ -63,16 +63,30 @@ async def proxy_request(path: str, request: Request):
return Response(content=error_xml, status_code=403, media_type="application/xml")
# Proxy request to MinIO
minio_url = f"{MINIO_ENDPOINT}/{path}"
headers = dict(request.headers)
async with httpx.AsyncClient(timeout=300.0) as client:
minio_url = f"{MINIO_ENDPOINT}/{path}"
headers = dict(request.headers)
body = await request.body()
logging.info(f"Proxying request to MinIO: {minio_url}")
if request.method in ["PUT", "POST"]:
# Stream request body to MinIO
async def request_stream():
async for chunk in request.stream():
yield chunk
minio_response = await client.request(
method=request.method, url=minio_url, headers=headers, content=body
)
minio_response = await client.request(
method=request.method,
url=minio_url,
headers=headers,
content=request_stream()
)
else:
# For GET and DELETE, we dont send a body
minio_response = await client.request(
method=request.method,
url=minio_url,
headers=headers
)
logging.info(f"MinIO response: {minio_response.status_code}")