Unverified Commit 2a51e0bc authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Feature-gate public use of `http-body` and `hyper` within `aws-smithy-types` (#3088)

## Motivation and Context
Implements https://github.com/awslabs/smithy-rs/issues/3033

## Description
This PR hides behind cargo features the third-party types from
`http-body` and `hyper` crates that are used in`aws-smithy-types`'
public API. Customers need to opt-in by enabling a cargo feature
`http-body-0-4-x` in `aws-smithy-types` to create an `SdkBody` or
`ByteStream` using those third-party types. For more details, please see
[the upgrade
guide](https://github.com/awslabs/smithy-rs/discussions/3089

).

As can been seen from code changes, to reduce the surface area where we
need to feature-gate things, we have fused the
`aws_smithy_types::body::Inner::Streaming` enum variant into
`aws_smithy_types::body::Inner::Dyn` variant, thereby removing
`SdkBody::from_dyn`.

## Testing
Relied on existing tests in CI

## Checklist
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or 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._

---------

Co-authored-by: default avatarZelda Hessler <zhessler@amazon.com>
parent 08a533ff
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -474,3 +474,15 @@ message = "Enable custom auth schemes to work by changing the code generated aut
references = ["smithy-rs#3034", "smithy-rs#3087"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client" }
author = "rcoh"

[[smithy-rs]]
message = "Publicly exposed types from `http-body` and `hyper` crates within `aws-smithy-types` are now feature-gated. See the [upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/3089) for details."
references = ["smithy-rs#3033", "smithy-rs#3088"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "ysaito1001"

[[smithy-rs]]
message = "`ByteStream::poll_next` is now feature-gated. You can turn on a cargo feature `byte-stream-poll-next` in `aws-smithy-types` to use it."
references = ["smithy-rs#3033", "smithy-rs#3088"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "ysaito1001"
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ aws-smithy-checksums = { path = "../../../rust-runtime/aws-smithy-checksums" }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
aws-smithy-runtime = { path = "../../../rust-runtime/aws-smithy-runtime", features = ["client"] }
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] }
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" }
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types", features = ["http-body-0-4-x"] }
bytes = "1"
hex = "0.4.3"
http = "0.2.9"
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{
use aws_smithy_runtime_api::client::interceptors::Intercept;
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::body::{BoxBody, SdkBody};
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
use aws_smithy_types::error::operation::BuildError;
use http::HeaderValue;
@@ -173,7 +173,7 @@ fn wrap_streaming_request_body_in_checksum_calculating_body(

            let body = AwsChunkedBody::new(body, aws_chunked_body_options);

            SdkBody::from_dyn(BoxBody::new(body))
            SdkBody::from_body_0_4(body)
        })
    };

@@ -269,7 +269,7 @@ mod tests {
        let crc32c_checksum = crc32c_checksum.finalize();

        let mut request = HttpRequest::new(
            ByteStream::read_from()
            ByteStream::read_with_body_0_4_from()
                .path(&file)
                .buffer_size(1024)
                .build()
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{
};
use aws_smithy_runtime_api::client::interceptors::Intercept;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::body::{BoxBody, SdkBody};
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
use http::HeaderValue;
use std::{fmt, mem};
@@ -119,11 +119,11 @@ pub(crate) fn wrap_body_with_checksum_validator(
    use aws_smithy_checksums::body::validate;

    body.map(move |body| {
        SdkBody::from_dyn(BoxBody::new(validate::ChecksumBody::new(
        SdkBody::from_body_0_4(validate::ChecksumBody::new(
            body,
            checksum_algorithm.into_impl(),
            precalculated_checksum.clone(),
        )))
        ))
    })
}

+5 −1
Original line number Diff line number Diff line
@@ -21,7 +21,11 @@ async fn set_correct_headers() {
    let _resp = client
        .upload_archive()
        .vault_name("vault")
        .body(ByteStream::from_path("tests/test-file.txt").await.unwrap())
        .body(
            ByteStream::from_path_body_0_4("tests/test-file.txt")
                .await
                .unwrap(),
        )
        .send()
        .await;
    let req = handler.expect_request();
Loading