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

This commit is contained in:
Lucas Fernandes Nogueira
2022-07-31 20:00:48 -03:00
committed by GitHub
parent ba5560b2a1
commit d576e8ae72
3 changed files with 19 additions and 2 deletions

View File

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

View File

@@ -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 {

View File

@@ -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
}