File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -537,14 +537,19 @@ def _serialize_cached_request_body_attribute(
537537 """
538538 Returns a stringified JSON representation of the request body if the request body is cached on the ASGI scope and within size bounds.
539539 """
540+ scope_state = request .scope .get ("state" , {})
540541 if (
541542 "content-length" not in request .headers
542- or _SCOPE_STATE_JSON_REQUEST_BODY_KEY not in request . scope [ "state" ]
543- and _SCOPE_STATE_FORMDATA_REQUEST_BODY_KEY not in request . scope [ "state" ]
543+ or _SCOPE_STATE_JSON_REQUEST_BODY_KEY not in scope_state
544+ and _SCOPE_STATE_FORMDATA_REQUEST_BODY_KEY not in scope_state
544545 ):
545546 return None
546547
547- content_length = int (request .headers ["content-length" ])
548+ try :
549+ content_length = int (request .headers ["content-length" ])
550+ except ValueError :
551+ return None
552+
548553 if content_length and not request_body_within_bounds (client , content_length ):
549554 return OVER_SIZE_LIMIT_SUBSTITUTE
550555
You can’t perform that action at this time.
0 commit comments