1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-19 04:15:38 +02:00

make streaming method more ergonomic

This commit is contained in:
Nikolay Kim
2018-03-21 19:14:18 -07:00
parent 2d75ced4ed
commit 4866a26578
2 changed files with 16 additions and 4 deletions

View File

@@ -516,10 +516,11 @@ impl HttpResponseBuilder {
/// Set a streaming body and generate `HttpResponse`.
///
/// `HttpResponseBuilder` can not be used after this call.
pub fn streaming<S>(&mut self, stream: S) -> Result<HttpResponse, HttpError>
where S: Stream<Item=Bytes, Error=Error> + 'static,
pub fn streaming<S, E>(&mut self, stream: S) -> Result<HttpResponse, HttpError>
where S: Stream<Item=Bytes, Error=E> + 'static,
E: Into<Error>,
{
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`