Unverified Commit 5b6965aa authored by Zelda Hessler's avatar Zelda Hessler Committed by GitHub
Browse files

Add conversion methods for `PresignedRequest` and update docs (#1116)

* update: s3 presigning example with curl command generator
add: impl into for PresignedRequest -> http::request::Builder
sort: cargo deps

* update: CHANGELOG.next.toml

* appease: clippy

* add: struct conversion doc links
add: fn for PresignedRequest -> http::Request<B>
update: expand presigning example

* update: changelog
move: declaration of From<PresignedRequest> for http::request::Builder

* remove: leftover import
parent 32923a33
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -11,6 +11,12 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[aws-sdk-rust]]
message = "Added `impl Into<http::request::Builder> for PresignedRequest` and a conversion method for turning `PresignedRequest`s into `http::Request`s."
references = ["aws-sdk-rust#423"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = "Convert several `info` spans to `debug` in aws-config"
references = ["smithy-rs#1087"]
+26 −0
Original line number Diff line number Diff line
@@ -151,6 +151,11 @@ pub mod request {
    use std::fmt::{Debug, Formatter};

    /// Represents a presigned request. This only includes the HTTP request method, URI, and headers.
    ///
    /// **This struct has conversion convenience functions:**
    ///
    /// - [`PresignedRequest::to_http_request<B>`][Self::to_http_request] returns an [`http::Request<B>`](https://docs.rs/http/0.2.6/http/request/struct.Request.html)
    /// - [`PresignedRequest::into`](#impl-From<PresignedRequest>) returns an [`http::request::Builder`](https://docs.rs/http/0.2.6/http/request/struct.Builder.html)
    #[non_exhaustive]
    pub struct PresignedRequest(http::Request<()>);

@@ -175,6 +180,13 @@ pub mod request {
        pub fn headers(&self) -> &http::HeaderMap<http::HeaderValue> {
            self.0.headers()
        }

        /// Given a body, convert this `PresignedRequest` into an `http::Request`
        pub fn to_http_request<B>(self, body: B) -> Result<http::Request<B>, http::Error> {
            let builder: http::request::Builder = self.into();

            builder.body(body)
        }
    }

    impl Debug for PresignedRequest {
@@ -186,6 +198,20 @@ pub mod request {
                .finish()
        }
    }

    impl From<PresignedRequest> for http::request::Builder {
        fn from(req: PresignedRequest) -> Self {
            let mut builder = http::request::Builder::new()
                .uri(req.uri())
                .method(req.method());

            if let Some(headers) = builder.headers_mut() {
                *headers = req.headers().clone();
            }

            builder
        }
    }
}

/// Tower middleware service for creating presigned requests