1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-21 09:23:54 +00: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

@ -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<S, E>(&mut self, stream: S) -> Result<ClientRequest, HttpError>
where S: Stream<Item=Bytes, Error=E> + 'static,
E: Into<Error>,
{
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.

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`