Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose streaming as public API wrap #2255

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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