From f6205afc0d0e419ecb56b9b6b04bd0a0cc9f62ca Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 10 Jun 2022 16:10:46 -0300 Subject: [PATCH] fix(core): wrong Content-Type when using reqwest's multipart, ref #4312 --- .changes/fix-reqwest-multipart.md | 5 +++++ core/tauri/src/api/http.rs | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changes/fix-reqwest-multipart.md diff --git a/.changes/fix-reqwest-multipart.md b/.changes/fix-reqwest-multipart.md new file mode 100644 index 000000000..240640445 --- /dev/null +++ b/.changes/fix-reqwest-multipart.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Fixes the `Content-Type` header value when sending multipart requests using the `reqwest-client` feature. diff --git a/core/tauri/src/api/http.rs b/core/tauri/src/api/http.rs index 7f34b5f9b..c051ef05b 100644 --- a/core/tauri/src/api/http.rs +++ b/core/tauri/src/api/http.rs @@ -238,7 +238,7 @@ impl Client { /// Executes an HTTP request /// /// # Examples - pub async fn send(&self, request: HttpRequestBuilder) -> crate::api::Result { + pub async fn send(&self, mut request: HttpRequestBuilder) -> crate::api::Result { let method = Method::from_bytes(request.method.to_uppercase().as_bytes())?; let mut request_builder = self.0.request(method, request.url.as_str()); @@ -260,7 +260,7 @@ impl Client { #[allow(unused_variables)] fn send_form( request_builder: reqwest::RequestBuilder, - headers: &Option, + headers: &mut Option, form_body: FormBody, ) -> crate::api::Result { #[cfg(feature = "http-multipart")] @@ -271,6 +271,8 @@ impl Client { .map(|v| v.as_bytes()), Some(b"multipart/form-data") ) { + // the Content-Type header will be set by reqwest in the `.multipart` call + headers.as_mut().map(|h| h.0.remove("content-type")); let mut multipart = reqwest::multipart::Form::new(); for (name, part) in form_body.0 { @@ -311,7 +313,7 @@ impl Client { } Ok(request_builder.form(&form)) } - send_form(request_builder, &request.headers, form_body)? + send_form(request_builder, &mut request.headers, form_body)? } }; }