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 Headers.get_as_optional_string and get_as_string #1114

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

muddyfish
Copy link
Contributor

Description of change

Refactors Headers to have two new public methods: get_as_optional_string and get_as_string.

Refactor head_object and put_object to use new header methods rather than custom implementations

Relevant 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).

@muddyfish muddyfish requested a review from dannycjones November 7, 2024 13:42
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 13:42 — with GitHub Actions Inactive
@muddyfish muddyfish requested a review from passaro November 7, 2024 13:59
dannycjones
dannycjones previously approved these changes Nov 7, 2024
Copy link
Contributor

@dannycjones dannycjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines 204 to 213
/// 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()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for both:

Suggested change
/// 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]>
@muddyfish muddyfish requested a review from dannycjones November 7, 2024 14:59
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
@muddyfish muddyfish temporarily deployed to PR integration tests November 7, 2024 14:59 — with GitHub Actions Inactive
Copy link
Contributor

@dannycjones dannycjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it!

@muddyfish muddyfish enabled auto-merge November 7, 2024 15:11
@muddyfish muddyfish added this pull request to the merge queue Nov 7, 2024
Merged via the queue into awslabs:main with commit 89e13a1 Nov 7, 2024
23 checks passed
@muddyfish muddyfish deleted the headers-get-as-string branch November 7, 2024 15:26
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.

2 participants