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

Add support for multipart/form-data bodies #258

Merged
merged 2 commits into from
Jun 9, 2024
Merged

Conversation

LucasPickering
Copy link
Owner

@LucasPickering LucasPickering commented Jun 9, 2024

Description

Describe the change. If there is an associated issue, please include the issue link (e.g. "Closes #xxx"). For UI changes, please also include screenshots.

This adds first-class support for multipart/form-data bodies, similar to the existing application/x-www-form-urlencoded bodies. This one was a bit more complicated, mainly because reqwest forces the body to be a stream rather than binary blob when using the multipart builder. So we're forced to turn plain bytes into a stream. This is annoying now but leaves us in an ok spot for #256. An example:

chains:
  image:
    source: !file
      path: ./static/slumber.png
requests:
  upload_image: !request
    name: Upload Image
    method: POST
    url: "{{host}}/anything/image"
    body: !form_multipart
      filename: "logo.png"
      image: "{{chains.image}}"

Closes #243

Known Risks

What issues could potentially go wrong with this change? Is it a breaking change? What have you done to mitigate any potential risks?

I haven't tested this much so there's totally room for an edge case. Also large files are forced to be loaded entirely into memory, which could create issues for some people.

QA

How did you test this?

Checklist

  • Have you read CONTRIBUTING.md already?
  • Did you update CHANGELOG.md?
    • Only user-facing changes belong in the changelog. Internal changes such as refactors should only be included if they'll impact users, e.g. via performance improvement.
  • Did you remove all TODOs?
    • If there are unresolved issues, please open a follow-on issue and link to it in a comment so future work can be tracked

The request view doesn't need ExchangeBody because it will never be queryable. This removes the only need for optional persistence. Overall this is making code less generic in the name of simplicity.
Add a new structured body type !form_multipart, which allows sending forms with binary data. This is a bit incomplete, we need to support streaming bodies in #256.

Closes #243
@LucasPickering LucasPickering merged commit fc30c64 into master Jun 9, 2024
15 checks passed
@LucasPickering LucasPickering deleted the form-multipart branch June 9, 2024 22:19
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.

First-class multipart/form-data support
1 participant