-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Implement multipart with multer #1033
Implement multipart with multer #1033
Conversation
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.
Thanks for writing this up so quickly! This is all set to go already?
src/filters/multipart.rs
Outdated
@@ -131,17 +123,18 @@ impl Stream for FormData { | |||
impl Part { | |||
/// Get the name of this part. | |||
pub fn name(&self) -> &str { | |||
&self.headers.name | |||
&self.part.name().unwrap_or("not-set") |
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.
Multipart fields exist without a name?
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.
Hey @seanmonstar, on the code there it points to the docs here https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition which says:
Only the value form-data, as well as the optional directive name and filename, can be used in the HTTP context.
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.
The subheading https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#as_a_header_for_a_multipart_body points out:
The first directive is always form-data, and the header must also include a name parameter to identify the relevant field.
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.
True.
Your concern is that if the library is not following the RFC or tat I should put a default that makes more sense on that?
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.
Either way, I will open an issue there to try to clarify. I am not sure if it is optional because it is used in both to represent both the header of HTTP and the boundary
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.
Sorry that I didn't explain more. I wasn't sure myself. So, I'm thinking that perhaps even if multer
doesn't think so yet, we would treat a lack of a name as an error, and thus if the name does exist, we can just use self.part.name().expect("checked for name previously")
. What do you think?
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.
all good but, the panic is ok there?
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.
Oh, what I was thinking is that constructing a Part
would require us to check for a name
, and if it doesn't exist, then next_field()
would return an Error
. We wouldn't want an unchecked panic that a client could trigger, no.
Hey @seanmonstar I guess so at least on my tests it was all good, any idea of edge cases to be tested there? |
bd14cd3
to
426c94c
Compare
ce654be
to
98872d8
Compare
…nd a part with a name field
57c7a1e
to
c6ac290
Compare
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.
Excellent work, thanks for taking this on!
This is a continuation of #846
@seanmonstar I've managed to implement the change to use multer without resorting to stream::unfold but, for that I had to implement a change on their project to expose the poll next item function.
So far,
cargo test --features=multipart
seems to work fine using that patch.I will open a PR there and check if it makes sense.