Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nested multipart, strict no-content parts CRLF and better part metadata resolution #380

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

fmigneault
Copy link

@fmigneault fmigneault commented Sep 24, 2024

Features and Fixes

  • Given a part that has "no content" (None) (as if it was returned on its own by an HTTP 204 No Content response), MultipartEncoder will not incorrectly insert a second \r\n anymore. A parser that strictly interprets the amount of \r\n can distinguish a "no content" part from an "empty string" part, which can have different meanings depending on the embedded Content-Type (e.g.: a null vs "" for JSON).

  • Fixes requests_toolbelt.multipart.decoder.ImproperBodyPartContentException: content does not contain CR-LF-CR-LF #352.
    Multipart decoder correctly understands a single \r\n used to separate the headers from the "no content" body. The resulting part returns None rather than "". A part still using CR-LF-CR-LF explicitly will enclose an empty string.

  • Add a content_type parameter to __init__ allowing to override the default multipart/form-data that was hard-coded.

  • Support nested multipart.
    Using the MultipartEncoder as file_pointer in the input fields of another MultipartEncoder will correctly nest the contents, with their respective boundaries. This can be used to form complex structures of multipart/mixed, multipart/alternate, multipart/related commonly used when combining various attachment representations.

  • When headers are provided for one of the parts, ensure that any Content-Type, Content-Location or Content-Disposition explicitly provided in them are not overridden by the urllib3.fields.make_multipart step. This allows using other dispositions than form-data, such as attachment or inline as needed.

@fmigneault fmigneault changed the title support nested multipart and no-conent parts support nested multipart, strict no-content parts CRLF and better part metadata resolution Sep 25, 2024
fmigneault added a commit to crim-ca/weaver that referenced this pull request Sep 25, 2024
@fmigneault
Copy link
Author

@sigmavirus24

Hi.
I would like to contribute these fixes and improvements for the multipart utilities.
Let me know if anything should be adjusted further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

requests_toolbelt.multipart.decoder.ImproperBodyPartContentException: content does not contain CR-LF-CR-LF
1 participant