mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
make streaming method more ergonomic
This commit is contained in:
parent
2d75ced4ed
commit
4866a26578
@ -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.
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user