From 6d1af6a3ee5888ceda96cd64c15819ec5b782c8f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 22 Apr 2024 22:39:59 +0800 Subject: [PATCH 1/3] feat: Expose streaming as public API Signed-off-by: Xuanwo --- src/async_impl/body.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index a70a853b1..32105edf7 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -137,8 +137,20 @@ impl Body { } } - // pub? - pub(crate) fn streaming(inner: B) -> Body + /// Wrap a [`HttpBody`] in a box inside `Body`. + /// + /// # Example + /// + /// ``` + /// # use reqwest::Body; + /// # use futures_util; + /// # fn main() { + /// let content = "hello,world!".to_string(); + /// + /// let body = Body::streaming(content); + /// # } + /// ``` + pub fn streaming(inner: B) -> Body where B: HttpBody + Send + Sync + 'static, B::Data: Into, From afb613c43fd26fa32e7e47ab9498ad1ab675c5f6 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 4 Sep 2024 22:48:54 +0800 Subject: [PATCH 2/3] Alter name to `wrap` --- src/async_impl/body.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index 32105edf7..e44fc4faf 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -116,17 +116,6 @@ impl Body { } } - /* - #[cfg(feature = "blocking")] - pub(crate) fn wrap(body: hyper::Body) -> Body { - Body { - inner: Inner::Streaming { - body: Box::pin(WrapHyper(body)), - }, - } - } - */ - pub(crate) fn empty() -> Body { Body::reusable(Bytes::new()) } @@ -147,10 +136,10 @@ impl Body { /// # fn main() { /// let content = "hello,world!".to_string(); /// - /// let body = Body::streaming(content); + /// let body = Body::wrap(content); /// # } /// ``` - pub fn streaming(inner: B) -> Body + pub fn wrap(inner: B) -> Body where B: HttpBody + Send + Sync + 'static, B::Data: Into, From fbabb3c3d835a428d0881ebe8ec14bc9e258d0d3 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 4 Sep 2024 22:54:17 +0800 Subject: [PATCH 3/3] Fix rename Signed-off-by: Xuanwo --- src/async_impl/body.rs | 2 +- src/async_impl/response.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index d545a0d19..c2f1257c1 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -484,7 +484,7 @@ mod tests { assert!(!bytes_body.is_end_stream()); assert_eq!(bytes_body.size_hint().exact(), Some(3)); - let stream_body = Body::streaming(bytes_body); + let stream_body = Body::wrap(bytes_body); assert!(!stream_body.is_end_stream()); assert_eq!(stream_body.size_hint().exact(), None); } diff --git a/src/async_impl/response.rs b/src/async_impl/response.rs index 17be37030..23e30d3ed 100644 --- a/src/async_impl/response.rs +++ b/src/async_impl/response.rs @@ -442,7 +442,7 @@ impl fmt::Debug for Response { /// A `Response` can be piped as the `Body` of another request. impl From for Body { fn from(r: Response) -> Body { - Body::streaming(r.res.into_body()) + Body::wrap(r.res.into_body()) } } @@ -477,7 +477,7 @@ impl> From> for Response { impl From for http::Response { fn from(r: Response) -> http::Response { let (parts, body) = r.res.into_parts(); - let body = Body::streaming(body); + let body = Body::wrap(body); http::Response::from_parts(parts, body) } }