diff --git a/rust-runtime/aws-smithy-types/Cargo.toml b/rust-runtime/aws-smithy-types/Cargo.toml index cbe5ddbf9ae..6b01bb0a786 100644 --- a/rust-runtime/aws-smithy-types/Cargo.toml +++ b/rust-runtime/aws-smithy-types/Cargo.toml @@ -10,13 +10,15 @@ edition = "2021" license = "Apache-2.0" repository = "https://github.com/smithy-lang/smithy-rs" +# DO NOT USE `dep:http-body-0-4` in this table. +# Doing so disables the implicit feature which we rely on internally. [features] byte-stream-poll-next = [] -http-body-0-4-x = ["dep:http-body-0-4"] -http-body-1-x = ["dep:http-body-1-0", "dep:http-body-util", "http-body-0-4-x"] +http-body-0-4-x = ["http-body-0-4"] +http-body-1-x = ["dep:http-body-1-0", "dep:http-body-util", "http-body-0-4", "http-1x"] hyper-0-14-x = ["dep:hyper-0-14"] rt-tokio = [ - "http-body-0-4-x", + "http-body-0-4", "dep:tokio-util", "dep:tokio", "tokio?/rt", @@ -33,7 +35,7 @@ base64-simd = "0.8" bytes = "1" bytes-utils = "0.1" http = "0.2.3" -http_1x = { package = "http", version = "1" } +http-1x = { package = "http", version = "1", optional = true } http-body-0-4 = { package = "http-body", version = "0.4.4", optional = true } http-body-1-0 = { package = "http-body", version = "1", optional = true } http-body-util = { version = "0.1.0", optional = true } diff --git a/rust-runtime/aws-smithy-types/additional-ci b/rust-runtime/aws-smithy-types/additional-ci index 2d9305d5103..7ce1a378ac5 100755 --- a/rust-runtime/aws-smithy-types/additional-ci +++ b/rust-runtime/aws-smithy-types/additional-ci @@ -12,3 +12,6 @@ cargo tree -d --edges normal --all-features echo "### Checking whether the features are properly feature-gated" ! cargo tree -e no-dev | grep serde + +echo "### Checking feature powerset" +cargo hack check --feature-powerset --exclude-all-features diff --git a/rust-runtime/aws-smithy-types/src/body.rs b/rust-runtime/aws-smithy-types/src/body.rs index d604a7416b3..bc693256e8e 100644 --- a/rust-runtime/aws-smithy-types/src/body.rs +++ b/rust-runtime/aws-smithy-types/src/body.rs @@ -57,7 +57,9 @@ impl Debug for SdkBody { /// A boxed generic HTTP body that, when consumed, will result in [`Bytes`] or an [`Error`]. enum BoxBody { - #[cfg(feature = "http-body-0-4-x")] + // This is enabled by the **dependency**, not the feature. This allows us to construct it + // whenever we have the dependency and keep the APIs private + #[cfg(feature = "http-body-0-4")] HttpBody04(http_body_0_4::combinators::BoxBody), } @@ -164,6 +166,23 @@ impl SdkBody { } } + #[cfg(feature = "http-body-0-4")] + pub(crate) fn from_body_0_4_internal(body: T) -> Self + where + T: http_body_0_4::Body + Send + Sync + 'static, + E: Into + 'static, + { + Self { + inner: Inner::Dyn { + inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new( + body.map_err(Into::into), + )), + }, + rebuild: None, + bytes_contents: None, + } + } + #[cfg(feature = "http-body-0-4-x")] pub(crate) fn poll_next_trailers( self: Pin<&mut Self>, diff --git a/rust-runtime/aws-smithy-types/src/body/http_body_0_4_x.rs b/rust-runtime/aws-smithy-types/src/body/http_body_0_4_x.rs index a6719d1fa2d..d4eae4cf4cc 100644 --- a/rust-runtime/aws-smithy-types/src/body/http_body_0_4_x.rs +++ b/rust-runtime/aws-smithy-types/src/body/http_body_0_4_x.rs @@ -3,11 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -use crate::body::{BoxBody, Error, Inner, SdkBody}; -use bytes::Bytes; use std::pin::Pin; use std::task::{Context, Poll}; +use bytes::Bytes; + +use crate::body::{Error, SdkBody}; + impl SdkBody { /// Construct an `SdkBody` from a type that implements [`http_body_0_4::Body`](http_body_0_4::Body). /// @@ -17,15 +19,7 @@ impl SdkBody { T: http_body_0_4::Body + Send + Sync + 'static, E: Into + 'static, { - Self { - inner: Inner::Dyn { - inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new( - body.map_err(Into::into), - )), - }, - rebuild: None, - bytes_contents: None, - } + SdkBody::from_body_0_4_internal(body) } } diff --git a/rust-runtime/aws-smithy-types/src/body/http_body_1_x.rs b/rust-runtime/aws-smithy-types/src/body/http_body_1_x.rs index 8e81a14da9a..48c8ebff563 100644 --- a/rust-runtime/aws-smithy-types/src/body/http_body_1_x.rs +++ b/rust-runtime/aws-smithy-types/src/body/http_body_1_x.rs @@ -12,26 +12,18 @@ use bytes::Bytes; use http_body_util::BodyExt; use pin_project_lite::pin_project; -use crate::body::{BoxBody, Error, Inner, SdkBody}; +use crate::body::{Error, SdkBody}; impl SdkBody { /// Construct an `SdkBody` from a type that implements [`http_body_1_0::Body`](http_body_1_0::Body). /// /// _Note: This is only available with `http-body-1-0` enabled._ - pub fn from_body_1_0(body: T) -> Self + pub fn from_body_1_x(body: T) -> Self where T: http_body_1_0::Body + Send + Sync + 'static, E: Into + 'static, { - Self { - inner: Inner::Dyn { - inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new( - Http1toHttp04::new(body.map_err(Into::into)), - )), - }, - rebuild: None, - bytes_contents: None, - } + SdkBody::from_body_0_4_internal(Http1toHttp04::new(body.map_err(Into::into))) } } @@ -59,19 +51,6 @@ where type Data = B::Data; type Error = B::Error; - /// - /// - /// # Arguments - /// - /// * `cx`: - /// - /// returns: Poll as Body>::Data, as Body>::Error>>> - /// - /// # Examples - /// - /// ``` - /// - /// ``` fn poll_data( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -146,17 +125,19 @@ fn convert_header_map(input: http_1x::HeaderMap) -> http::HeaderMap { #[cfg(test)] mod test { - use crate::body::http_body_1_x::convert_header_map; - use crate::body::{Error, SdkBody}; - use crate::byte_stream::ByteStream; + use std::collections::VecDeque; + use std::pin::Pin; + use std::task::{Context, Poll}; + use bytes::Bytes; use http::header::{CONTENT_LENGTH as CL0, CONTENT_TYPE as CT0}; use http_1x::header::{CONTENT_LENGTH as CL1, CONTENT_TYPE as CT1}; use http_1x::{HeaderMap, HeaderName, HeaderValue}; use http_body_1_0::Frame; - use std::collections::VecDeque; - use std::pin::Pin; - use std::task::{Context, Poll}; + + use crate::body::http_body_1_x::convert_header_map; + use crate::body::{Error, SdkBody}; + use crate::byte_stream::ByteStream; struct TestBody { chunks: VecDeque, @@ -216,7 +197,7 @@ mod test { ] .into(), }; - let body = SdkBody::from_body_1_0(body); + let body = SdkBody::from_body_1_x(body); let data = ByteStream::new(body); assert_eq!(data.collect().await.unwrap().to_vec(), b"123456789"); } @@ -232,7 +213,7 @@ mod test { ] .into(), }; - let mut body = SdkBody::from_body_1_0(body); + let mut body = SdkBody::from_body_1_x(body); while let Some(_data) = http_body_0_4::Body::data(&mut body).await {} assert_eq!( http_body_0_4::Body::trailers(&mut body).await.unwrap(), @@ -252,7 +233,7 @@ mod test { .into(), }; - let body = SdkBody::from_body_1_0(body); + let body = SdkBody::from_body_1_x(body); let body = ByteStream::new(body); body.collect().await.expect_err("body returned an error"); } @@ -262,7 +243,7 @@ mod test { chunks: vec![Chunk::Data("123"), Chunk::Data("456"), Chunk::Data("789")].into(), }; - let body = SdkBody::from_body_1_0(body); + let body = SdkBody::from_body_1_x(body); let body = ByteStream::new(body); assert_eq!(body.collect().await.unwrap().to_vec(), b"123456789"); } diff --git a/rust-runtime/aws-smithy-types/src/byte_stream/bytestream_util.rs b/rust-runtime/aws-smithy-types/src/byte_stream/bytestream_util.rs index 39965c90c56..2ed7341eeb6 100644 --- a/rust-runtime/aws-smithy-types/src/byte_stream/bytestream_util.rs +++ b/rust-runtime/aws-smithy-types/src/byte_stream/bytestream_util.rs @@ -193,7 +193,7 @@ impl FsBuilder { let body_loader = move || { // If an offset was provided, seeking will be handled in `PathBody::poll_data` each // time the file is loaded. - SdkBody::from_body_0_4(PathBody::from_path( + SdkBody::from_body_0_4_internal(PathBody::from_path( path.clone(), length, buffer_size, @@ -208,7 +208,8 @@ impl FsBuilder { let _s = file.seek(io::SeekFrom::Start(offset)).await?; } - let body = SdkBody::from_body_0_4(PathBody::from_file(file, length, buffer_size)); + let body = + SdkBody::from_body_0_4_internal(PathBody::from_file(file, length, buffer_size)); Ok(ByteStream::new(body)) } else { diff --git a/rust-runtime/aws-smithy-types/src/byte_stream/http_body_1_x.rs b/rust-runtime/aws-smithy-types/src/byte_stream/http_body_1_x.rs index 803de6bf78a..eacb7540d12 100644 --- a/rust-runtime/aws-smithy-types/src/byte_stream/http_body_1_x.rs +++ b/rust-runtime/aws-smithy-types/src/byte_stream/http_body_1_x.rs @@ -18,6 +18,6 @@ impl ByteStream { T: http_body_1_0::Body + Send + Sync + 'static, E: Into + 'static, { - ByteStream::new(SdkBody::from_body_1_0(body)) + ByteStream::new(SdkBody::from_body_1_x(body)) } }