Selaa lähdekoodia

fix(core): wrong Content-Type when using reqwest's multipart, ref #4312

Lucas Nogueira 3 vuotta sitten
vanhempi
sitoutus
f6205afc0d
2 muutettua tiedostoa jossa 10 lisäystä ja 3 poistoa
  1. 5 0
      .changes/fix-reqwest-multipart.md
  2. 5 3
      core/tauri/src/api/http.rs

+ 5 - 0
.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.

+ 5 - 3
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<Response> {
+  pub async fn send(&self, mut request: HttpRequestBuilder) -> crate::api::Result<Response> {
     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<HeaderMap>,
+            headers: &mut Option<HeaderMap>,
             form_body: FormBody,
           ) -> crate::api::Result<reqwest::RequestBuilder> {
             #[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)?
         }
       };
     }