diff --git a/src/client/request.rs b/src/client/request.rs index 449bb642b..f446c8845 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -5,9 +5,10 @@ use std::time::Duration; use actix::{Addr, Unsync}; use cookie::{Cookie, CookieJar}; -use bytes::{BytesMut, BufMut}; +use bytes::{Bytes, BytesMut, BufMut}; use http::{uri, HeaderMap, Method, Version, Uri, HttpTryFrom, Error as HttpError}; use http::header::{self, HeaderName, HeaderValue}; +use futures::Stream; use serde_json; use serde::Serialize; use percent_encoding::{USERINFO_ENCODE_SET, percent_encode}; @@ -591,6 +592,16 @@ impl ClientRequestBuilder { Ok(self.body(body)?) } + /// Set a streaming body and generate `ClientRequest`. + /// + /// `ClientRequestBuilder` can not be used after this call. + pub fn streaming(&mut self, stream: S) -> Result + where S: Stream + 'static, + E: Into, + { + self.body(Body::Streaming(Box::new(stream.map_err(|e| e.into())))) + } + /// Set an empty body and generate `ClientRequest` /// /// `ClientRequestBuilder` can not be used after this call. diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 52327d6e7..7bfaac7be 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -516,10 +516,11 @@ impl HttpResponseBuilder { /// Set a streaming body and generate `HttpResponse`. /// /// `HttpResponseBuilder` can not be used after this call. - pub fn streaming(&mut self, stream: S) -> Result - where S: Stream + 'static, + pub fn streaming(&mut self, stream: S) -> Result + where S: Stream + 'static, + E: Into, { - self.body(Body::Streaming(Box::new(stream))) + self.body(Body::Streaming(Box::new(stream.map_err(|e| e.into())))) } /// Set a json body and generate `HttpResponse`