Skip to content

Commit 4cc8ec8

Browse files
authored
feat: Expose streaming as public API wrap (#2255)
1 parent cc3dd51 commit 4cc8ec8

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/async_impl/body.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ impl Body {
117117
}
118118
}
119119

120-
/*
121-
#[cfg(feature = "blocking")]
122-
pub(crate) fn wrap(body: hyper::Body) -> Body {
123-
Body {
124-
inner: Inner::Streaming {
125-
body: Box::pin(WrapHyper(body)),
126-
},
127-
}
128-
}
129-
*/
130-
131120
pub(crate) fn empty() -> Body {
132121
Body::reusable(Bytes::new())
133122
}
@@ -138,8 +127,20 @@ impl Body {
138127
}
139128
}
140129

141-
// pub?
142-
pub(crate) fn streaming<B>(inner: B) -> Body
130+
/// Wrap a [`HttpBody`] in a box inside `Body`.
131+
///
132+
/// # Example
133+
///
134+
/// ```
135+
/// # use reqwest::Body;
136+
/// # use futures_util;
137+
/// # fn main() {
138+
/// let content = "hello,world!".to_string();
139+
///
140+
/// let body = Body::wrap(content);
141+
/// # }
142+
/// ```
143+
pub fn wrap<B>(inner: B) -> Body
143144
where
144145
B: HttpBody + Send + Sync + 'static,
145146
B::Data: Into<Bytes>,
@@ -483,7 +484,7 @@ mod tests {
483484
assert!(!bytes_body.is_end_stream());
484485
assert_eq!(bytes_body.size_hint().exact(), Some(3));
485486

486-
let stream_body = Body::streaming(bytes_body);
487+
let stream_body = Body::wrap(bytes_body);
487488
assert!(!stream_body.is_end_stream());
488489
assert_eq!(stream_body.size_hint().exact(), None);
489490
}

src/async_impl/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl fmt::Debug for Response {
442442
/// A `Response` can be piped as the `Body` of another request.
443443
impl From<Response> for Body {
444444
fn from(r: Response) -> Body {
445-
Body::streaming(r.res.into_body())
445+
Body::wrap(r.res.into_body())
446446
}
447447
}
448448

@@ -477,7 +477,7 @@ impl<T: Into<Body>> From<http::Response<T>> for Response {
477477
impl From<Response> for http::Response<Body> {
478478
fn from(r: Response) -> http::Response<Body> {
479479
let (parts, body) = r.res.into_parts();
480-
let body = Body::streaming(body);
480+
let body = Body::wrap(body);
481481
http::Response::from_parts(parts, body)
482482
}
483483
}

0 commit comments

Comments
 (0)