mirror of https://github.com/fafhrd91/actix-web
add multipart for client
This commit is contained in:
parent
e9fe3879df
commit
bc43372ba4
|
@ -126,6 +126,9 @@ webpki-roots = { version = "0.15", optional = true }
|
|||
# unix sockets
|
||||
tokio-uds = { version="0.2", optional = true }
|
||||
|
||||
#multipart for client
|
||||
multipart-rfc7578 = "0.6"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
|
|
|
@ -40,6 +40,7 @@ pub(crate) use self::pipeline::Pipeline;
|
|||
pub use self::pipeline::{SendRequest, SendRequestError};
|
||||
pub use self::request::{ClientRequest, ClientRequestBuilder};
|
||||
pub use self::response::ClientResponse;
|
||||
pub use multipart_rfc7578::Form as MultipartForm;
|
||||
pub(crate) use self::writer::HttpClientWriter;
|
||||
|
||||
use error::ResponseError;
|
||||
|
|
|
@ -12,6 +12,7 @@ use serde::Serialize;
|
|||
use serde_json;
|
||||
use serde_urlencoded;
|
||||
use url::Url;
|
||||
use multipart_rfc7578::{Form, Body as MultipartBody};
|
||||
|
||||
use super::connector::{ClientConnector, Connection};
|
||||
use super::pipeline::SendRequest;
|
||||
|
@ -709,6 +710,18 @@ impl ClientRequestBuilder {
|
|||
self.body(body)
|
||||
}
|
||||
|
||||
/// Set a multipart body and generate `ClientRequest`.
|
||||
///
|
||||
/// `ClientRequestBuilder` can not be used after this call.
|
||||
pub fn multipart(&mut self, form: Form) -> Result<ClientRequest, Error>
|
||||
{
|
||||
self.header(header::CONTENT_TYPE, form.content_type());
|
||||
if let Some(len) = form.content_length() {
|
||||
self.header(header::CONTENT_LENGTH, len.to_string());
|
||||
}
|
||||
self.streaming(MultipartBody::from(form))
|
||||
}
|
||||
|
||||
/// Set a streaming body and generate `ClientRequest`.
|
||||
///
|
||||
/// `ClientRequestBuilder` can not be used after this call.
|
||||
|
|
|
@ -114,6 +114,7 @@ extern crate net2;
|
|||
extern crate parking_lot;
|
||||
extern crate rand;
|
||||
extern crate slab;
|
||||
extern crate multipart_rfc7578;
|
||||
extern crate tokio;
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio_io;
|
||||
|
|
Loading…
Reference in New Issue