-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 API for Headers on Parts of Multipart Form Data #331
Conversation
Being able to set headers for a part seems reasonable. I'd suggest that instead of a |
ccdc831
to
e5a3189
Compare
I've switched to |
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.
Looking good! I'm not worried yet about the lower-casing, it can dealt with in the future if it causes problems.
src/multipart_.rs
Outdated
use http; | ||
|
||
/// An alias to http::HeaderMap so http is unneded as an explicit dependency | ||
pub type HeaderMap = http::HeaderMap<String>; |
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'd remove this alias, and use the default http::HeaderMap
which uses HeaderValue
instead of String
.
src/multipart_.rs
Outdated
@@ -197,6 +203,21 @@ impl Part { | |||
self.file_name = Some(filename.into()); | |||
self | |||
} | |||
|
|||
/// Returns a reference to the map of additional header fields | |||
pub fn header_fields(&self) -> &HeaderMap { |
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.
To match with the other APIs, I'd call this method just headers
.
src/multipart_.rs
Outdated
} | ||
|
||
/// Returns a mutable reference to the map of additional header fields | ||
pub fn header_fields_mut(&mut self) -> &mut HeaderMap { |
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.
And this method could be named headers_mut
.
src/multipart_.rs
Outdated
} | ||
|
||
/// Replaces the additional header fields | ||
pub fn replace_header_fields(&mut self, hdr: HeaderMap) -> () { |
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.
This method shouldn't be needed, as anyone can do the same with std::mem::replace
combined with headers_mut
.
src/multipart_.rs
Outdated
@@ -205,6 +226,7 @@ impl fmt::Debug for Part { | |||
.field("value", &self.value) | |||
.field("mime", &self.mime) | |||
.field("file_name", &self.file_name) | |||
.field("hdr", &self.hdr) |
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.
For debugging, we may as well call it the full word, headers
.
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 renamed the struct field, too…
src/multipart_.rs
Outdated
field.hdr.iter().fold( | ||
"".to_string(), | ||
|hdrs, (k,v)| | ||
format!("{}\r\n{}: {}", hdrs, k.as_str(), v) |
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.
This will actually allocate a new string for each header, whereas they could just be pushed onto the existing one... Though, there shouldn't be that many for a single part, so it's probably not a big deal.
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 hope + on String does what I think it does.
0bb0824
to
e520e9f
Compare
Review implemented and rebased on master (with |
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.
Awesome, thanks for sticking with it!
Thank you for merging and enhancing it. (And sorry for the delay. I was moving over the weekend.) |
When working on rust-ipfs-api, I saw that it uses a somewhat uncommon format for some requests:
The
Abspath
header on the form data part is critical: it tells the server where to find the file on hard disk if it needs to re-read it later. (Whether that is good design…)This PR does add a patch that allows composing requests like the above, but considering my unfamiliarity with Rust and the discussion in #312 I doubt that you want to accept it like this. If possible, I'd like you to consider this a feature request, and a request to tell me how to implement the functionality properly.