Skip to content

Commit

Permalink
Ensure that all form data is read to content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Crighton committed Aug 12, 2023
1 parent de85289 commit 005adc0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion phew/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,14 @@ async def _handle_request(self, reader, writer):
if request.headers["content-type"].startswith("application/json"):
request.data = await _parse_json_body(reader, request.headers)
if request.headers["content-type"].startswith("application/x-www-form-urlencoded"):
form_data = await reader.read(int(request.headers["content-length"]))
form_data = b""
content_length = int(request.headers["content-length"])
while content_length > 0:
data = await reader.read(content_length)
if len(data) == 0:
break
content_length -= len(data)
form_data += data
request.form = _parse_query_string(form_data.decode())

route = self._match_route(request)
Expand Down

0 comments on commit 005adc0

Please sign in to comment.