Make multipart an optional feature (default off) (#1128)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "multipart")]
|
||||
use super::multipart::Form;
|
||||
/// dox
|
||||
use bytes::Bytes;
|
||||
@@ -18,6 +19,7 @@ pub struct Body {
|
||||
|
||||
enum Inner {
|
||||
Bytes(Bytes),
|
||||
#[cfg(feature = "multipart")]
|
||||
Multipart(Form),
|
||||
}
|
||||
|
||||
@@ -30,6 +32,7 @@ impl Body {
|
||||
let js_value: &JsValue = body_array.as_ref();
|
||||
Ok(js_value.to_owned())
|
||||
}
|
||||
#[cfg(feature = "multipart")]
|
||||
Inner::Multipart(form) => {
|
||||
let form_data = form.to_form_data()?;
|
||||
let js_value: &JsValue = form_data.as_ref();
|
||||
@@ -39,6 +42,7 @@ impl Body {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "multipart")]
|
||||
pub(crate) fn from_form(f: Form) -> Body {
|
||||
Self {
|
||||
inner: Inner::Multipart(f),
|
||||
@@ -48,6 +52,7 @@ impl Body {
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
match &self.inner {
|
||||
Inner::Bytes(bytes) => bytes.is_empty(),
|
||||
#[cfg(feature = "multipart")]
|
||||
Inner::Multipart(form) => form.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ mod client;
|
||||
mod request;
|
||||
mod response;
|
||||
/// TODO
|
||||
#[cfg(feature = "multipart")]
|
||||
pub mod multipart;
|
||||
|
||||
pub use self::body::Body;
|
||||
|
||||
@@ -191,6 +191,7 @@ impl RequestBuilder {
|
||||
}
|
||||
|
||||
/// TODO
|
||||
#[cfg(feature = "multipart")]
|
||||
pub fn multipart(mut self, multipart: super::multipart::Form) -> RequestBuilder {
|
||||
if let Ok(ref mut req) = self.request {
|
||||
*req.body_mut() = Some(Body::from_form(multipart))
|
||||
|
||||
Reference in New Issue
Block a user