Unverified Commit 684605ae authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Http updates (#3059)

## Motivation and Context
- [ ] Upgrade guidance
- [x] changelog

To allow seamless adoption of the incoming `http` crate, we're updating
our client crates to use an intermediate type.

## Description

Update _client_ code to use `HttpRequest`. Some internal code still uses
`http::Request` but those usages are limited.

## Testing
CI

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 63ce3f95
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -378,3 +378,15 @@ message = """Several traits have been renamed from noun form to verb form to be
references = ["smithy-rs#3065"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[smithy-rs]]
message = "**This change has [detailed upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/3067)**. A summary is below.<br><br> The `HttpRequest` type alias now points to `aws-smithy-runtime-api::client::http::Request`. This is a first-party request type to allow us to gracefully support `http = 1.0` when it arrives. Most customer code using this method should be unaffected. `TryFrom`/`TryInto` conversions are provided for `http = 0.2.*`."
references = ["smithy-rs#3059"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "rcoh"

[[aws-sdk-rust]]
message = "[`PresignedRequest`](https://docs.rs/aws-sdk-s3/latest/aws_sdk_s3/presigning/struct.PresignedRequest.html) now returns standard-library types instead of types from the `http` crate. `to_http_request` has been renamed `to_http_02x_request`."
references = ["smithy-rs#3059"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"
+5 −1
Original line number Diff line number Diff line
@@ -135,7 +135,11 @@ impl Builder {
                if let Some(auth) = input.auth {
                    http_req = http_req.header(AUTHORIZATION, auth);
                }
                Ok(http_req.body(SdkBody::empty()).expect("valid request"))
                Ok(http_req
                    .body(SdkBody::empty())
                    .expect("valid request")
                    .try_into()
                    .unwrap())
            })
            .deserializer(move |response| parse_response(provider_name, response))
            .build();
+14 −5
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ use aws_smithy_runtime_api::client::endpoint::{
    EndpointFuture, EndpointResolverParams, ResolveEndpoint,
};
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
use aws_smithy_runtime_api::client::orchestrator::{OrchestratorError, SensitiveOutput};
use aws_smithy_runtime_api::client::orchestrator::{
    HttpRequest, OrchestratorError, SensitiveOutput,
};
use aws_smithy_runtime_api::client::retries::classifiers::{
    ClassifyRetry, RetryAction, SharedRetryClassifier,
};
@@ -435,10 +437,13 @@ impl Builder {
            ))
            .with_connection_poisoning()
            .serializer(|path| {
                Ok(http::Request::builder()
                Ok(HttpRequest::try_from(
                    http::Request::builder()
                        .uri(path)
                        .body(SdkBody::empty())
                    .expect("valid request"))
                        .expect("valid request"),
                )
                .unwrap())
            })
            .deserializer(|response| {
                if response.status().is_success() {
@@ -626,6 +631,8 @@ pub(crate) mod test {
            .method("PUT")
            .body(SdkBody::empty())
            .unwrap()
            .try_into()
            .unwrap()
    }

    pub(crate) fn token_response(ttl: u32, token: &'static str) -> HttpResponse {
@@ -643,6 +650,8 @@ pub(crate) mod test {
            .header("x-aws-ec2-metadata-token", token)
            .body(SdkBody::empty())
            .unwrap()
            .try_into()
            .unwrap()
    }

    pub(crate) fn imds_response(body: &'static str) -> HttpResponse {
+3 −1
Original line number Diff line number Diff line
@@ -137,7 +137,9 @@ impl TokenResolver {
                            .uri(Uri::from_static("/latest/api/token"))
                            .header(X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS, token_ttl.as_secs())
                            .body(SdkBody::empty())
                            .expect("valid HTTP request"))
                            .expect("valid HTTP request")
                            .try_into()
                            .unwrap())
                    })
                    .deserializer({
                        let time_source = time_source.clone();
+3 −9
Original line number Diff line number Diff line
@@ -383,7 +383,7 @@ mod test {
        let req = request.expect_request();
        let str_body = std::str::from_utf8(req.body().bytes().unwrap()).unwrap();
        assert!(str_body.contains("1234567"), "{}", str_body);
        assert_eq!(req.uri(), "https://sts.us-east-1.amazonaws.com");
        assert_eq!(req.uri(), "https://sts.us-east-1.amazonaws.com/");
    }

    #[tokio::test]
@@ -411,7 +411,7 @@ mod test {
            .await;
        let _ = dbg!(provider.provide_credentials().await);
        let req = request.expect_request();
        assert_eq!(req.uri(), "https://sts.us-west-2.amazonaws.com");
        assert_eq!(req.uri(), "https://sts.us-west-2.amazonaws.com/");
    }

    /// Test that `build()` where no provider is passed still works
@@ -442,13 +442,7 @@ mod test {
            .await;
        let _ = provider.provide_credentials().await;
        let req = request.expect_request();
        let auth_header = req
            .headers()
            .get(AUTHORIZATION)
            .unwrap()
            .to_str()
            .unwrap()
            .to_string();
        let auth_header = req.headers().get(AUTHORIZATION).unwrap().to_string();
        let expect = "Credential=123-key/20090213/us-west-17/sts/aws4_request";
        assert!(
            auth_header.contains(expect),
Loading