diff --git a/examples/client_json.rs b/examples/client_json.rs index ef92f14b10..04ca6f7d91 100644 --- a/examples/client_json.rs +++ b/examples/client_json.rs @@ -28,6 +28,7 @@ async fn fetch_json(url: hyper::Uri) -> Result> { let res = client.get(url).await?; // asynchronously aggregate the chunks of the body + #[allow(deprecated)] let body = hyper::body::aggregate(res).await?; // try to parse as json with serde_json diff --git a/examples/echo.rs b/examples/echo.rs index ff7573049e..ff13085004 100644 --- a/examples/echo.rs +++ b/examples/echo.rs @@ -34,6 +34,7 @@ async fn echo(req: Request) -> Result, hyper::Error> { // So here we do `.await` on the future, waiting on concatenating the full body, // then afterwards the content can be reversed. Only then can we return a `Response`. (&Method::POST, "/echo/reversed") => { + #[allow(deprecated)] let whole_body = hyper::body::to_bytes(req.into_body()).await?; let reversed_body = whole_body.iter().rev().cloned().collect::>(); diff --git a/examples/params.rs b/examples/params.rs index 87c2368928..8c9d923788 100644 --- a/examples/params.rs +++ b/examples/params.rs @@ -17,6 +17,7 @@ async fn param_example(req: Request) -> Result, hyper::Erro (&Method::GET, "/") | (&Method::GET, "/post") => Ok(Response::new(INDEX.into())), (&Method::POST, "/post") => { // Concatenate the body... + #[allow(deprecated)] let b = hyper::body::to_bytes(req).await?; // Parse the request body. form_urlencoded::parse // always succeeds, but in general parsing may diff --git a/examples/web_api.rs b/examples/web_api.rs index 5226249b35..6e6fea311a 100644 --- a/examples/web_api.rs +++ b/examples/web_api.rs @@ -40,6 +40,7 @@ async fn client_request_response(client: &Client) -> Result) -> Result> { // Aggregate the body... + #[allow(deprecated)] let whole_body = hyper::body::aggregate(req).await?; // Decode as JSON... let mut data: serde_json::Value = serde_json::from_reader(whole_body.reader())?; diff --git a/src/body/aggregate.rs b/src/body/aggregate.rs index 99662419d3..4bce1767ff 100644 --- a/src/body/aggregate.rs +++ b/src/body/aggregate.rs @@ -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(body: T) -> Result where T: HttpBody, diff --git a/src/body/mod.rs b/src/body/mod.rs index 5e2181e941..109b1e6b72 100644 --- a/src/body/mod.rs +++ b/src/body/mod.rs @@ -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; diff --git a/src/body/to_bytes.rs b/src/body/to_bytes.rs index 038c6fd0f3..2e398d250a 100644 --- a/src/body/to_bytes.rs +++ b/src/body/to_bytes.rs @@ -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(body: T) -> Result where T: HttpBody, diff --git a/tests/client.rs b/tests/client.rs index 88fcd3a564..9d7bf08335 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -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}; @@ -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"); diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 3b116aef34..5a641faaf8 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -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"); @@ -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| {