diff --git a/rust-runtime/aws-smithy-runtime-api/src/client/http/request.rs b/rust-runtime/aws-smithy-runtime-api/src/client/http/request.rs index 8619c2841a..5b4172160d 100644 --- a/rust-runtime/aws-smithy-runtime-api/src/client/http/request.rs +++ b/rust-runtime/aws-smithy-runtime-api/src/client/http/request.rs @@ -380,7 +380,7 @@ impl Headers { key: impl AsHeaderComponent, value: impl AsHeaderComponent, ) -> Result, HttpError> { - let key = header_name(key.into_maybe_static()?)?; + let key = header_name(key)?; let value = header_value(value.into_maybe_static()?)?; Ok(self .headers @@ -404,8 +404,10 @@ impl Headers { /// Removes all headers with a given key /// /// If there are multiple entries for this key, the first entry is returned - pub fn remove(&mut self, key: &str) -> Option { - self.headers.remove(key) + pub fn remove(&mut self, key: impl AsRef) -> Option { + self.headers + .remove(key.as_ref()) + .map(|h| h.as_str().to_string()) } /// Appends a value to a given key @@ -427,6 +429,9 @@ mod sealed { /// If the component can be represented as a Cow<'static, str>, return it fn into_maybe_static(self) -> Result; + /// Return a string reference to this header + fn as_str(&self) -> Result<&str, HttpError>; + /// If a component is already internally represented as a `http02x::HeaderName`, return it fn repr_as_http02x_header_name(self) -> Result where @@ -440,18 +445,30 @@ mod sealed { fn into_maybe_static(self) -> Result { Ok(Cow::Borrowed(self)) } + + fn as_str(&self) -> Result<&str, HttpError> { + Ok(self) + } } impl AsHeaderComponent for String { fn into_maybe_static(self) -> Result { Ok(Cow::Owned(self)) } + + fn as_str(&self) -> Result<&str, HttpError> { + Ok(self) + } } impl AsHeaderComponent for Cow<'static, str> { fn into_maybe_static(self) -> Result { Ok(self) } + + fn as_str(&self) -> Result<&str, HttpError> { + Ok(self.as_ref()) + } } impl AsHeaderComponent for http0::HeaderValue { @@ -462,6 +479,10 @@ mod sealed { .to_string(), )) } + + fn as_str(&self) -> Result<&str, HttpError> { + std::str::from_utf8(self.as_bytes()).map_err(HttpError::header_was_not_a_string) + } } impl AsHeaderComponent for http0::HeaderName { @@ -469,6 +490,10 @@ mod sealed { Ok(self.to_string().into()) } + fn as_str(&self) -> Result<&str, HttpError> { + Ok(self.as_ref()) + } + fn repr_as_http02x_header_name(self) -> Result where Self: Sized, diff --git a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs index 11f7d873df..85b70ac5c4 100644 --- a/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs +++ b/rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs @@ -132,7 +132,7 @@ fn apply_endpoint( for (header_name, header_values) in endpoint.headers() { request.headers_mut().remove(header_name); for value in header_values { - request.headers_mut().insert( + request.headers_mut().append( HeaderName::from_str(header_name).map_err(|err| { ResolveEndpointError::message("invalid header name") .with_source(Some(err.into()))