Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 multipart/form-data response builders to axum-extra #2654
base: main
Are you sure you want to change the base?
Add multipart/form-data response builders to axum-extra #2654
Changes from 5 commits
1fb8685
dfa4fa0
345fd56
f64975c
c8ccb72
7cde253
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "builder"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a
Multipart
extractor, so I wanted to clarify between that and the functionality for creating forms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be named so it's clearer what it does, e.g.
add_part
orpush_part
.Personally, I'm not also sure this API is that useful,wouldn't it be better to just have something like
parts_mut
which would return a mutable reference to the parts vector and then the user can just push there directly, but also remove stuff, clear it, or any other operation they might need to take.On the other hand they can just build the vector beforehand and then call
from_parts
just before returning the response.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it did feel kind of odd, I was trying to create something similar to Reqwest's implementation (
.part()
) chained calls, but with.with_parts()
it feels redundant, so I removed it. I can addparts_mut
if you feel it would prudent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already depend on
mime
so I'd suggest using that to construct the string. It could avoid some typo bugs. It would be great if it would be possible to use it also for the multi part content type. I don't know if it's possible with the dynamic boundary though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now all of the
Part::*
constructors return Self directly, butPart::raw_part
relies on a mime type passed in as an argument.I know that it's generally considered bad practice to add third party crates to the public api without good cause, but the only other option I can see here is having the function internally parse the provided string into a valid mime type, which should return a result, making this portion of the interface a little bit clunkier.
Thoughts? I could include mime in the public interface, or change the interface to return a result, making it less ergonomic.