get rid of unwraps

This commit is contained in:
Thiago Arrais 2020-11-03 13:45:04 -03:00
parent 17e9d203ee
commit e7d96288cd
2 changed files with 17 additions and 16 deletions

View File

@ -56,6 +56,7 @@ serde_json = "1.0"
serde_urlencoded = "0.7" serde_urlencoded = "0.7"
open-ssl = { version = "0.10", package = "openssl", optional = true } open-ssl = { version = "0.10", package = "openssl", optional = true }
rust-tls = { version = "0.18.0", package = "rustls", optional = true, features = ["dangerous_configuration"] } rust-tls = { version = "0.18.0", package = "rustls", optional = true, features = ["dangerous_configuration"] }
if_chain = "1.0.1"
[dev-dependencies] [dev-dependencies]
actix-connect = { version = "2.0.0", features = ["openssl"] } actix-connect = { version = "2.0.0", features = ["openssl"] }

View File

@ -1,3 +1,4 @@
use if_chain::if_chain;
use std::cell::RefCell; use std::cell::RefCell;
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
@ -135,15 +136,13 @@ where
match resp { match resp {
Ok((resphead, payload)) => { Ok((resphead, payload)) => {
if resphead.status.is_redirection() { if_chain! {
reqhead.uri = resphead if resphead.status.is_redirection();
.headers if let Some(location_value) = resphead.headers.get(actix_http::http::header::LOCATION);
.get(actix_http::http::header::LOCATION) if let Ok(location_str) = location_value.to_str();
.unwrap() if let Ok(location_uri) = location_str.parse::<Uri>();
.to_str() then {
.unwrap() reqhead.uri = location_uri;
.parse::<Uri>()
.unwrap();
return deal_with_redirects( return deal_with_redirects(
backend.clone(), backend.clone(),
reqhead, reqhead,
@ -152,6 +151,7 @@ where
) )
.await; .await;
} }
}
Ok(ClientResponse::new(resphead, payload)) Ok(ClientResponse::new(resphead, payload))
} }
Err(e) => Err(e), Err(e) => Err(e),