Skip to content

Commit

Permalink
feat: Expose streaming as public API wrap (#2255)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored Sep 4, 2024
1 parent cc3dd51 commit 4cc8ec8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,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())
}
Expand All @@ -138,8 +127,20 @@ impl Body {
}
}

// pub?
pub(crate) fn streaming<B>(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::wrap(content);
/// # }
/// ```
pub fn wrap<B>(inner: B) -> Body
where
B: HttpBody + Send + Sync + 'static,
B::Data: Into<Bytes>,
Expand Down Expand Up @@ -483,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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/async_impl/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl fmt::Debug for Response {
/// A `Response` can be piped as the `Body` of another request.
impl From<Response> for Body {
fn from(r: Response) -> Body {
Body::streaming(r.res.into_body())
Body::wrap(r.res.into_body())
}
}

Expand Down Expand Up @@ -477,7 +477,7 @@ impl<T: Into<Body>> From<http::Response<T>> for Response {
impl From<Response> for http::Response<Body> {
fn from(r: Response) -> http::Response<Body> {
let (parts, body) = r.res.into_parts();
let body = Body::streaming(body);
let body = Body::wrap(body);
http::Response::from_parts(parts, body)
}
}
Expand Down

0 comments on commit 4cc8ec8

Please sign in to comment.