diff --git a/src/wasm/body.rs b/src/wasm/body.rs index 43a2e82..ab2160f 100644 --- a/src/wasm/body.rs +++ b/src/wasm/body.rs @@ -44,6 +44,13 @@ impl Body { inner: Inner::Multipart(f), } } + + pub(crate) fn is_empty(&self) -> bool { + match &self.inner { + Inner::Bytes(bytes) => bytes.is_empty(), + Inner::Multipart(form) => form.is_empty(), + } + } } impl From for Body { diff --git a/src/wasm/client.rs b/src/wasm/client.rs index 47059dd..8f8d634 100644 --- a/src/wasm/client.rs +++ b/src/wasm/client.rs @@ -158,7 +158,9 @@ async fn fetch(req: Request) -> crate::Result { } if let Some(body) = req.body() { - init.body(Some(&body.to_js_value()?.as_ref().as_ref())); + if !body.is_empty() { + init.body(Some(&body.to_js_value()?.as_ref().as_ref())); + } } let js_req = web_sys::Request::new_with_str_and_init(req.url().as_str(), &init) diff --git a/src/wasm/multipart.rs b/src/wasm/multipart.rs index 09150cc..66d6432 100644 --- a/src/wasm/multipart.rs +++ b/src/wasm/multipart.rs @@ -13,6 +13,12 @@ pub struct Form { inner: FormParts, } +impl Form { + pub(crate) fn is_empty(&self) -> bool { + self.inner.fields.is_empty() + } +} + /// A field in a multipart form. pub struct Part { meta: PartMetadata,