From 7e7f368e4f677ccc1c08c2b76447e736e04be242 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 8 Dec 2023 13:22:02 -0500 Subject: [PATCH] feat(body): deprecate to_bytes() and aggregate() --- src/body/aggregate.rs | 7 +++++++ src/body/mod.rs | 2 ++ src/body/to_bytes.rs | 7 +++++++ tests/client.rs | 3 ++- tests/support/mod.rs | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) 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| {