Skip to content

Commit 36c60e1

Browse files
committed
Ensure http-body-0-4 is not inadvertently publicly exposed
1 parent 0dfc603 commit 36c60e1

File tree

7 files changed

+52
-52
lines changed

7 files changed

+52
-52
lines changed

rust-runtime/aws-smithy-types/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ edition = "2021"
1010
license = "Apache-2.0"
1111
repository = "https://github.com/smithy-lang/smithy-rs"
1212

13+
# DO NOT USE `dep:http-body-0-4` in this table.
14+
# Doing so disables the implicit feature which we rely on internally.
1315
[features]
1416
byte-stream-poll-next = []
15-
http-body-0-4-x = ["dep:http-body-0-4"]
16-
http-body-1-x = ["dep:http-body-1-0", "dep:http-body-util", "http-body-0-4-x"]
17+
http-body-0-4-x = ["http-body-0-4"]
18+
http-body-1-x = ["dep:http-body-1-0", "dep:http-body-util", "http-body-0-4"]
1719
hyper-0-14-x = ["dep:hyper-0-14"]
1820
rt-tokio = [
19-
"http-body-0-4-x",
21+
"http-body-0-4",
2022
"dep:tokio-util",
2123
"dep:tokio",
2224
"tokio?/rt",

rust-runtime/aws-smithy-types/additional-ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ cargo tree -d --edges normal --all-features
1212

1313
echo "### Checking whether the features are properly feature-gated"
1414
! cargo tree -e no-dev | grep serde
15+
16+
echo "### Checking feature powerset"
17+
cargo hack check --feature-powerset --exclude-all-features

rust-runtime/aws-smithy-types/src/body.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ impl Debug for SdkBody {
5757

5858
/// A boxed generic HTTP body that, when consumed, will result in [`Bytes`] or an [`Error`].
5959
enum BoxBody {
60-
#[cfg(feature = "http-body-0-4-x")]
60+
// This is enabled by the **dependency**, not the feature. This allows us to construct it
61+
// whenever we have the dependency and keep the APIs private
62+
#[cfg(feature = "http-body-0-4")]
6163
HttpBody04(http_body_0_4::combinators::BoxBody<Bytes, Error>),
6264
}
6365

@@ -164,6 +166,23 @@ impl SdkBody {
164166
}
165167
}
166168

169+
#[cfg(feature = "http-body-0-4")]
170+
pub(crate) fn from_body_0_4_internal<T, E>(body: T) -> Self
171+
where
172+
T: http_body_0_4::Body<Data = Bytes, Error = E> + Send + Sync + 'static,
173+
E: Into<Error> + 'static,
174+
{
175+
Self {
176+
inner: Inner::Dyn {
177+
inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new(
178+
body.map_err(Into::into),
179+
)),
180+
},
181+
rebuild: None,
182+
bytes_contents: None,
183+
}
184+
}
185+
167186
#[cfg(feature = "http-body-0-4-x")]
168187
pub(crate) fn poll_next_trailers(
169188
self: Pin<&mut Self>,

rust-runtime/aws-smithy-types/src/body/http_body_0_4_x.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
use crate::body::{BoxBody, Error, Inner, SdkBody};
7-
use bytes::Bytes;
86
use std::pin::Pin;
97
use std::task::{Context, Poll};
108

9+
use bytes::Bytes;
10+
11+
use crate::body::{Error, SdkBody};
12+
1113
impl SdkBody {
1214
/// Construct an `SdkBody` from a type that implements [`http_body_0_4::Body<Data = Bytes>`](http_body_0_4::Body).
1315
///
@@ -17,15 +19,7 @@ impl SdkBody {
1719
T: http_body_0_4::Body<Data = Bytes, Error = E> + Send + Sync + 'static,
1820
E: Into<Error> + 'static,
1921
{
20-
Self {
21-
inner: Inner::Dyn {
22-
inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new(
23-
body.map_err(Into::into),
24-
)),
25-
},
26-
rebuild: None,
27-
bytes_contents: None,
28-
}
22+
SdkBody::from_body_0_4_internal(body)
2923
}
3024
}
3125

rust-runtime/aws-smithy-types/src/body/http_body_1_x.rs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,18 @@ use bytes::Bytes;
1212
use http_body_util::BodyExt;
1313
use pin_project_lite::pin_project;
1414

15-
use crate::body::{BoxBody, Error, Inner, SdkBody};
15+
use crate::body::{Error, SdkBody};
1616

1717
impl SdkBody {
1818
/// Construct an `SdkBody` from a type that implements [`http_body_1_0::Body<Data = Bytes>`](http_body_1_0::Body).
1919
///
2020
/// _Note: This is only available with `http-body-1-0` enabled._
21-
pub fn from_body_1_0<T, E>(body: T) -> Self
21+
pub fn from_body_1_x<T, E>(body: T) -> Self
2222
where
2323
T: http_body_1_0::Body<Data = Bytes, Error = E> + Send + Sync + 'static,
2424
E: Into<Error> + 'static,
2525
{
26-
Self {
27-
inner: Inner::Dyn {
28-
inner: BoxBody::HttpBody04(http_body_0_4::combinators::BoxBody::new(
29-
Http1toHttp04::new(body.map_err(Into::into)),
30-
)),
31-
},
32-
rebuild: None,
33-
bytes_contents: None,
34-
}
26+
SdkBody::from_body_0_4_internal(Http1toHttp04::new(body.map_err(Into::into)))
3527
}
3628
}
3729

@@ -59,19 +51,6 @@ where
5951
type Data = B::Data;
6052
type Error = B::Error;
6153

62-
///
63-
///
64-
/// # Arguments
65-
///
66-
/// * `cx`:
67-
///
68-
/// returns: Poll<Option<Result<<Http1toHttp04<B> as Body>::Data, <Http1toHttp04<B> as Body>::Error>>>
69-
///
70-
/// # Examples
71-
///
72-
/// ```
73-
///
74-
/// ```
7554
fn poll_data(
7655
mut self: Pin<&mut Self>,
7756
cx: &mut Context<'_>,
@@ -146,17 +125,19 @@ fn convert_header_map(input: http_1x::HeaderMap) -> http::HeaderMap {
146125

147126
#[cfg(test)]
148127
mod test {
149-
use crate::body::http_body_1_x::convert_header_map;
150-
use crate::body::{Error, SdkBody};
151-
use crate::byte_stream::ByteStream;
128+
use std::collections::VecDeque;
129+
use std::pin::Pin;
130+
use std::task::{Context, Poll};
131+
152132
use bytes::Bytes;
153133
use http::header::{CONTENT_LENGTH as CL0, CONTENT_TYPE as CT0};
154134
use http_1x::header::{CONTENT_LENGTH as CL1, CONTENT_TYPE as CT1};
155135
use http_1x::{HeaderMap, HeaderName, HeaderValue};
156136
use http_body_1_0::Frame;
157-
use std::collections::VecDeque;
158-
use std::pin::Pin;
159-
use std::task::{Context, Poll};
137+
138+
use crate::body::http_body_1_x::convert_header_map;
139+
use crate::body::{Error, SdkBody};
140+
use crate::byte_stream::ByteStream;
160141

161142
struct TestBody {
162143
chunks: VecDeque<Chunk>,
@@ -216,7 +197,7 @@ mod test {
216197
]
217198
.into(),
218199
};
219-
let body = SdkBody::from_body_1_0(body);
200+
let body = SdkBody::from_body_1_x(body);
220201
let data = ByteStream::new(body);
221202
assert_eq!(data.collect().await.unwrap().to_vec(), b"123456789");
222203
}
@@ -232,7 +213,7 @@ mod test {
232213
]
233214
.into(),
234215
};
235-
let mut body = SdkBody::from_body_1_0(body);
216+
let mut body = SdkBody::from_body_1_x(body);
236217
while let Some(_data) = http_body_0_4::Body::data(&mut body).await {}
237218
assert_eq!(
238219
http_body_0_4::Body::trailers(&mut body).await.unwrap(),
@@ -252,7 +233,7 @@ mod test {
252233
.into(),
253234
};
254235

255-
let body = SdkBody::from_body_1_0(body);
236+
let body = SdkBody::from_body_1_x(body);
256237
let body = ByteStream::new(body);
257238
body.collect().await.expect_err("body returned an error");
258239
}
@@ -262,7 +243,7 @@ mod test {
262243
chunks: vec![Chunk::Data("123"), Chunk::Data("456"), Chunk::Data("789")].into(),
263244
};
264245

265-
let body = SdkBody::from_body_1_0(body);
246+
let body = SdkBody::from_body_1_x(body);
266247
let body = ByteStream::new(body);
267248
assert_eq!(body.collect().await.unwrap().to_vec(), b"123456789");
268249
}

rust-runtime/aws-smithy-types/src/byte_stream/bytestream_util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl FsBuilder {
193193
let body_loader = move || {
194194
// If an offset was provided, seeking will be handled in `PathBody::poll_data` each
195195
// time the file is loaded.
196-
SdkBody::from_body_0_4(PathBody::from_path(
196+
SdkBody::from_body_0_4_internal(PathBody::from_path(
197197
path.clone(),
198198
length,
199199
buffer_size,
@@ -208,7 +208,8 @@ impl FsBuilder {
208208
let _s = file.seek(io::SeekFrom::Start(offset)).await?;
209209
}
210210

211-
let body = SdkBody::from_body_0_4(PathBody::from_file(file, length, buffer_size));
211+
let body =
212+
SdkBody::from_body_0_4_internal(PathBody::from_file(file, length, buffer_size));
212213

213214
Ok(ByteStream::new(body))
214215
} else {

rust-runtime/aws-smithy-types/src/byte_stream/http_body_1_x.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ impl ByteStream {
1818
T: http_body_1_0::Body<Data = Bytes, Error = E> + Send + Sync + 'static,
1919
E: Into<crate::body::Error> + 'static,
2020
{
21-
ByteStream::new(SdkBody::from_body_1_0(body))
21+
ByteStream::new(SdkBody::from_body_1_x(body))
2222
}
2323
}

0 commit comments

Comments
 (0)