File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,22 @@ def prepare_response_headers(
115115 return headers
116116
117117
118+ def _read_body_with_content_length (
119+ environ : WSGIEnvironment , content_length : int
120+ ) -> bytes :
121+ bytes_read = 0
122+ chunks = []
123+ input_stream : BytesIO = environ ["wsgi.input" ]
124+ while bytes_read < content_length :
125+ to_read = content_length - bytes_read
126+ chunk = input_stream .read (to_read )
127+ if not chunk :
128+ break
129+ chunks .append (chunk )
130+ bytes_read += len (chunk )
131+ return b"" .join (chunks )
132+
133+
118134def _read_body (environ : WSGIEnvironment ) -> Iterator [bytes ]:
119135 input_stream : BytesIO = environ ["wsgi.input" ]
120136 while True :
@@ -257,7 +273,7 @@ def _handle_post_request(
257273 content_length = environ .get ("CONTENT_LENGTH" )
258274 content_length = 0 if not content_length else int (content_length )
259275 if content_length > 0 :
260- req_body = environ [ "wsgi.input" ]. read ( content_length )
276+ req_body = _read_body_with_content_length ( environ , content_length )
261277 else :
262278 req_body = b"" .join (_read_body (environ ))
263279
You can’t perform that action at this time.
0 commit comments