Skip to content

Commit

Permalink
fix multipart decoder to allow no-contents part (fixes requests#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Sep 24, 2024
1 parent 0b79aea commit 94e7f4b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions requests_toolbelt/multipart/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ def __init__(self, content, encoding):
first, self.content = _split_on_find(content, b'\r\n\r\n')
if first != b'':
headers = _header_parser(first.lstrip(), encoding)
# because pre-split by boundary was done,
# having only a single newline and the '--'
# means that this is a 'no content' part
elif content.endswith(b'\r\n') and not content.endswith(b'\r\n\r\n'):
self.content = None
headers = _header_parser(content.strip(), encoding)
if not headers:
raise ImproperBodyPartContentException(
'No contents part without any header is invalid.'
)
else:
print("==" + content.decode() + "===")
raise ImproperBodyPartContentException(
'content does not contain CR-LF-CR-LF'
)
Expand All @@ -68,6 +79,8 @@ def __init__(self, content, encoding):
@property
def text(self):
"""Content of the ``BodyPart`` in unicode."""
if self.content is None:
return None
return self.content.decode(self.encoding)


Expand Down

0 comments on commit 94e7f4b

Please sign in to comment.