Explorar el Código

feat(core): do not follow redirects if `max_redirects` is 0 closes #4795 (#4812)

Lucas Fernandes Nogueira hace 3 años
padre
commit
d576e8ae72
Se han modificado 3 ficheros con 19 adiciones y 2 borrados
  1. 5 0
      .changes/skip-redirects.md
  2. 10 2
      core/tauri/src/api/http.rs
  3. 4 0
      tooling/api/src/http.ts

+ 5 - 0
.changes/skip-redirects.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Do not follow redirects when `api::http::ClientBuilder::max_redirections` is `0`.

+ 10 - 2
core/tauri/src/api/http.rs

@@ -84,7 +84,11 @@ impl ClientBuilder {
     let mut client_builder = reqwest::Client::builder();
 
     if let Some(max_redirections) = self.max_redirections {
-      client_builder = client_builder.redirect(reqwest::redirect::Policy::limited(max_redirections))
+      client_builder = client_builder.redirect(if max_redirections == 0 {
+        reqwest::redirect::Policy::none()
+      } else {
+        reqwest::redirect::Policy::limited(max_redirections)
+      });
     }
 
     if let Some(connect_timeout) = self.connect_timeout {
@@ -142,7 +146,11 @@ impl Client {
     }
 
     if let Some(max_redirections) = self.0.max_redirections {
-      request_builder = request_builder.max_redirections(max_redirections as u32);
+      if max_redirections == 0 {
+        request_builder = request_builder.follow_redirects(false);
+      } else {
+        request_builder = request_builder.max_redirections(max_redirections as u32);
+      }
     }
 
     if let Some(timeout) = request.timeout {

+ 4 - 0
tooling/api/src/http.ts

@@ -52,6 +52,10 @@ interface Duration {
 
 interface ClientOptions {
   maxRedirections?: number
+  /**
+   * Defines the maximum number of redirects the client should follow.
+   * If set to 0, no redirects will be followed.
+   */
   connectTimeout?: number | Duration
 }