diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 3c1963d6b..d0d2a71d9 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -56,6 +56,7 @@ serde_json = "1.0" serde_urlencoded = "0.7" open-ssl = { version = "0.10", package = "openssl", optional = true } rust-tls = { version = "0.18.0", package = "rustls", optional = true, features = ["dangerous_configuration"] } +if_chain = "1.0.1" [dev-dependencies] actix-connect = { version = "2.0.0", features = ["openssl"] } diff --git a/awc/src/connect.rs b/awc/src/connect.rs index 96b8b29ef..1a1b55d19 100644 --- a/awc/src/connect.rs +++ b/awc/src/connect.rs @@ -1,3 +1,4 @@ +use if_chain::if_chain; use std::cell::RefCell; use std::future::Future; use std::pin::Pin; @@ -135,22 +136,21 @@ where match resp { Ok((resphead, payload)) => { - if resphead.status.is_redirection() { - reqhead.uri = resphead - .headers - .get(actix_http::http::header::LOCATION) - .unwrap() - .to_str() - .unwrap() - .parse::() - .unwrap(); - return deal_with_redirects( - backend.clone(), - reqhead, - reqbody, - addr, - ) - .await; + if_chain! { + if resphead.status.is_redirection(); + if let Some(location_value) = resphead.headers.get(actix_http::http::header::LOCATION); + if let Ok(location_str) = location_value.to_str(); + if let Ok(location_uri) = location_str.parse::(); + then { + reqhead.uri = location_uri; + return deal_with_redirects( + backend.clone(), + reqhead, + reqbody, + addr, + ) + .await; + } } Ok(ClientResponse::new(resphead, payload)) }