-
Notifications
You must be signed in to change notification settings - Fork 174
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 Headers.get_as_optional_string
and get_as_string
#1114
Conversation
Signed-off-by: Simon Beal <[email protected]>
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.
LGTM!
/// Get a single header by name as a string. | ||
pub fn get_as_string<H: AsRef<OsStr>>(&self, name: H) -> Result<String, HeadersError> { | ||
let header = self.get(name)?; | ||
let value = header.value(); | ||
if let Some(s) = value.to_str() { | ||
Ok(s.to_string()) | ||
} else { | ||
Err(HeadersError::Invalid(value.clone())) | ||
} | ||
} |
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.
nit for both:
/// Get a single header by name as a string. | |
pub fn get_as_string<H: AsRef<OsStr>>(&self, name: H) -> Result<String, HeadersError> { | |
let header = self.get(name)?; | |
let value = header.value(); | |
if let Some(s) = value.to_str() { | |
Ok(s.to_string()) | |
} else { | |
Err(HeadersError::Invalid(value.clone())) | |
} | |
} | |
/// Get a single header by name as a [String]. | |
pub fn get_as_string<H: AsRef<OsStr>>(&self, name: H) -> Result<String, HeadersError> { | |
let header = self.get(name)?; | |
let value = header.value(); | |
if let Some(s) = value.to_str() { | |
Ok(s.to_string()) | |
} else { | |
Err(HeadersError::Invalid(value.clone())) | |
} | |
} |
Signed-off-by: Simon Beal <[email protected]>
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.
Ship it!
Description of change
Refactors
Headers
to have two new public methods:get_as_optional_string
andget_as_string
.Refactor
head_object
andput_object
to use new header methods rather than custom implementationsRelevant issues: N/A
Does this change impact existing behavior?
Changes log format slightly by making "Header string was not valid" text part of HeadersError.
Does this change need a changelog entry in any of the crates?
No
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the Developer Certificate of Origin (DCO).