fix _read_request_body (#7706)

This commit is contained in:
Ishaan Jaff 2025-01-11 21:54:51 -08:00 committed by GitHub
parent 71e679246a
commit 7923cb1a64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
import json
from typing import Dict, List, Optional
import orjson
from fastapi import Request, UploadFile, status
from litellm._logging import verbose_proxy_logger
@ -32,13 +33,10 @@ async def _read_request_body(request: Optional[Request]) -> Dict:
if not body:
return {}
# Decode the body to a string
body_str = body.decode()
# Attempt JSON parsing (safe for untrusted input)
return json.loads(body_str)
return orjson.loads(body)
except json.JSONDecodeError:
except (json.JSONDecodeError, orjson.JSONDecodeError):
# Log detailed information for debugging
verbose_proxy_logger.exception("Invalid JSON payload received.")
return {}