Skip to content

Commit

Permalink
Better handle chain redirection detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrech committed May 13, 2024
1 parent 085f5a1 commit 692a7b1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/api/redirection_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ impl RedirectionLoop {
}

if i > 1 {
// If the url cannot be parsed, let's treat it as a relative Url.
// Otherwise, we check if the corresponding domain is registered in the project.
if let Ok(url) = Url::parse(&current_url) {
if !project_domains.is_empty() && !project_domains.contains(&url.host_str().unwrap().to_string()) {
// The current url target a domain that is not registered in the project.
// So we consider there is no redirection loop here.
break;
}
}

error = Some(RedirectionError::AtLeastOneHop);
}

Expand All @@ -131,6 +121,16 @@ impl RedirectionLoop {
method: current_method.clone(),
});

// If the url cannot be parsed, let's treat it as a relative Url.
// Otherwise, we check if the corresponding domain is registered in the project.
if let Ok(url) = Url::parse(&current_url) {
if !project_domains.is_empty() && !project_domains.contains(&url.host_str().unwrap().to_string()) {
// The current url target a domain that is not registered in the project.
// So we consider there is no redirection loop here.
break;
}
}

if i >= max_hops {
error = Some(RedirectionError::TooManyHops);
break;
Expand Down

0 comments on commit 692a7b1

Please sign in to comment.