mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
This reverts commit 95183f2103
.
This commit is contained in:
parent
87c7da0eb3
commit
f778865836
1 changed files with 6 additions and 12 deletions
|
@ -21,32 +21,26 @@ async def _read_request_body(request: Optional[Request]) -> Dict:
|
||||||
try:
|
try:
|
||||||
if request is None:
|
if request is None:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# Check if we already read and parsed the body
|
|
||||||
if hasattr(request.state, "parsed_body"):
|
|
||||||
return request.state.parsed_body
|
|
||||||
|
|
||||||
_request_headers: dict = _safe_get_request_headers(request=request)
|
_request_headers: dict = _safe_get_request_headers(request=request)
|
||||||
content_type = _request_headers.get("content-type", "")
|
content_type = _request_headers.get("content-type", "")
|
||||||
|
|
||||||
if "form" in content_type:
|
if "form" in content_type:
|
||||||
parsed_body = dict(await request.form())
|
return dict(await request.form())
|
||||||
else:
|
else:
|
||||||
# Read the request body
|
# Read the request body
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
|
|
||||||
# Return empty dict if body is empty or None
|
# Return empty dict if body is empty or None
|
||||||
if not body:
|
if not body:
|
||||||
parsed_body = {}
|
return {}
|
||||||
parsed_body = orjson.loads(body)
|
|
||||||
|
|
||||||
# Cache the parsed result
|
# Attempt JSON parsing (safe for untrusted input)
|
||||||
request.state.parsed_body = parsed_body
|
return orjson.loads(body)
|
||||||
return parsed_body
|
|
||||||
|
|
||||||
except (json.JSONDecodeError, orjson.JSONDecodeError):
|
except (json.JSONDecodeError, orjson.JSONDecodeError):
|
||||||
|
# Log detailed information for debugging
|
||||||
verbose_proxy_logger.exception("Invalid JSON payload received.")
|
verbose_proxy_logger.exception("Invalid JSON payload received.")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Catch unexpected errors to avoid crashes
|
# Catch unexpected errors to avoid crashes
|
||||||
verbose_proxy_logger.exception(
|
verbose_proxy_logger.exception(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue