Skip to content

Commit

Permalink
Accept utf-8 encoded header values when parsing multipart requests
Browse files Browse the repository at this point in the history
This is done to enable passing in utf-8 filenames in headers.
  • Loading branch information
ayys committed Jan 12, 2024
1 parent 3b0df43 commit 637b36f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions graphql_server/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ def _split_on_find(content, bound):


def _header_parser(string):

headers = email.parser.HeaderParser().parsestr(string.decode("ascii")).items()
return {k: v.encode("ascii") for k, v in headers}
headers = email.parser.HeaderParser().parsestr(string.decode("utf-8")).items()
return {k: v.encode("utf-8") for k, v in headers}


class BodyPart(object):
Expand Down Expand Up @@ -146,13 +145,13 @@ def parse_header(line):
will be decoded later.
"""
plist = _parse_header_params(b";" + line)
key = plist.pop(0).lower().decode("ascii")
key = plist.pop(0).lower().decode("utf-8")
pdict = {}
for p in plist:
i = p.find(b"=")
if i >= 0:
has_encoding = False
name = p[:i].strip().lower().decode("ascii")
name = p[:i].strip().lower().decode("utf-8")
if name.endswith("*"):
# Lang/encoding embedded in the value (like "filename*=UTF-8''file.ext")
# https://tools.ietf.org/html/rfc2231#section-4
Expand Down

0 comments on commit 637b36f

Please sign in to comment.