Skip to content

Commit

Permalink
Add Clone impl to PresignedRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Oct 20, 2023
1 parent 66a3acf commit 140b4d0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions aws/rust-runtime/aws-inlineable/src/presigning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
use aws_smithy_types::body::SdkBody;
use std::fmt;
use std::time::{Duration, SystemTime};

Expand Down Expand Up @@ -175,10 +176,21 @@ impl PresigningConfigBuilder {
#[non_exhaustive]
pub struct PresignedRequest(HttpRequest);

impl Clone for PresignedRequest {
fn clone(&self) -> Self {
Self(
self.0
.try_clone()
.expect("presigned requests do not have a body"),
)
}
}

impl PresignedRequest {
#[allow(dead_code)]
pub(crate) fn new(inner: HttpRequest) -> Self {
Self(inner)
// throw out the body so we're sure it's cloneable
Self(inner.map(|_body| SdkBody::empty()))
}

/// Returns the HTTP request method.
Expand All @@ -198,8 +210,13 @@ impl PresignedRequest {
self.0.headers().iter()
}

/// Given a body, convert this `PresignedRequest` into an `http::Request`
pub fn to_http_02x_request<B>(self, body: B) -> Result<http::Request<B>, BoxError> {
/// Given a body, produce an `http::Request` from this `PresignedRequest`
pub fn make_http_02x_request<B>(&self, body: B) -> Result<http::Request<B>, BoxError> {
self.clone().into_http_02x_request(body)
}

/// Converts this `PresignedRequest` directly into an `http` request.
pub fn into_http_02x_request<B>(self, body: B) -> Result<http::Request<B>, BoxError> {
Ok(self.0.into_http02x()?.map(|_req| body))
}
}
Expand Down

0 comments on commit 140b4d0

Please sign in to comment.