From 7be4d3a0f44da0f5096702ce34665ddffd631660 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Wed, 2 Apr 2025 12:50:18 -0400 Subject: [PATCH] We should stream the Chunks for PUT requests. --- nginx_request_checker.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/nginx_request_checker.py b/nginx_request_checker.py index c65c992..eeadc8e 100644 --- a/nginx_request_checker.py +++ b/nginx_request_checker.py @@ -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 don’t 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}")