Skip to content

Commit

Permalink
feat(body): deprecate to_bytes() and aggregate()
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 8, 2023
1 parent ad50497 commit 7e7f368
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/body/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ use crate::common::buf::BufList;
/// Care needs to be taken if the remote is untrusted. The function doesn't implement any length
/// checks and an malicious peer might make it consume arbitrary amounts of memory. Checking the
/// `Content-Length` is a possibility, but it is not strictly mandated to be present.
#[cfg_attr(
feature = "deprecated",
deprecated(
note = "This function has been replaced by a method on the `hyper::body::HttpBody` trait. Use `.collect().await?.aggregate()` instead."
)
)]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
where
T: HttpBody,
Expand Down
2 changes: 2 additions & 0 deletions src/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ pub use bytes::{Buf, Bytes};
pub use http_body::Body as HttpBody;
pub use http_body::SizeHint;

#[cfg_attr(feature = "deprecated", allow(deprecated))]
pub use self::aggregate::aggregate;
pub use self::body::{Body, Sender};
pub(crate) use self::length::DecodedLength;
#[cfg_attr(feature = "deprecated", allow(deprecated))]
pub use self::to_bytes::to_bytes;

mod aggregate;
Expand Down
7 changes: 7 additions & 0 deletions src/body/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ use super::HttpBody;
/// # Ok(())
/// # }
/// ```
#[cfg_attr(
feature = "deprecated",
deprecated(
note = "This function has been replaced by a method on the `hyper::body::HttpBody` trait. Use `.collect().await?.to_bytes()` instead."
)
)]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
pub async fn to_bytes<T>(body: T) -> Result<Bytes, T::Error>
where
T: HttpBody,
Expand Down
3 changes: 2 additions & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;

#[allow(deprecated)]
use hyper::body::to_bytes as concat;
use hyper::{Body, Client, Method, Request, StatusCode};

Expand Down Expand Up @@ -3202,7 +3203,7 @@ mod conn {
let resp = client.send_request(req).await.expect("send_request");
assert!(resp.status().is_success());

let body = hyper::body::to_bytes(resp.into_body())
let body = concat(resp.into_body())
.await
.expect("get response body with no error");

Expand Down
2 changes: 2 additions & 0 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ async fn async_test(cfg: __TestConfig) {
func(&req.headers());
}
let sbody = sreq.body;
#[allow(deprecated)]
hyper::body::to_bytes(req).map_ok(move |body| {
assert_eq!(body.as_ref(), sbody.as_slice(), "client body");

Expand Down Expand Up @@ -433,6 +434,7 @@ async fn async_test(cfg: __TestConfig) {
for func in &cheaders {
func(&res.headers());
}
#[allow(deprecated)]
hyper::body::to_bytes(res)
})
.map_ok(move |body| {
Expand Down

0 comments on commit 7e7f368

Please sign in to comment.