diff --git a/requests_toolbelt/multipart/decoder.py b/requests_toolbelt/multipart/decoder.py index 2a0d1c4..c39c5db 100644 --- a/requests_toolbelt/multipart/decoder.py +++ b/requests_toolbelt/multipart/decoder.py @@ -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' ) @@ -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)