Skip to content

Commit

Permalink
feat(core): do not follow redirects if max_redirects is 0 closes #4795
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 31, 2022
1 parent ba5560b commit d576e8a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/skip-redirects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Do not follow redirects when `api::http::ClientBuilder::max_redirections` is `0`.
12 changes: 10 additions & 2 deletions core/tauri/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions tooling/api/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d576e8a

Please sign in to comment.