add multipart for client

This commit is contained in:
Marat Safin 2018-08-19 10:15:22 +03:00
parent e9fe3879df
commit bc43372ba4
4 changed files with 18 additions and 0 deletions

View File

@ -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"

View File

@ -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;

View File

@ -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.

View File

@ -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;