diff options
Diffstat (limited to 'src/https.rs')
-rw-r--r-- | src/https.rs | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/https.rs b/src/https.rs index d621cfe..83eca7c 100644 --- a/src/https.rs +++ b/src/https.rs @@ -9,7 +9,7 @@ use log::*; use accept_encoding_fork::Encoding; use async_compression::tokio::bufread::*; use futures::stream::FuturesUnordered; -use futures::{Future, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt}; use http::header::{HeaderName, HeaderValue}; use http::method::Method; use hyper::server::conn::Http; @@ -25,7 +25,6 @@ use crate::cert_store::{CertStore, StoreResolver}; use crate::proxy_config::ProxyConfig; use crate::reverse_proxy; -const PROXY_TIMEOUT: Duration = Duration::from_secs(60); const MAX_CONNECTION_LIFETIME: Duration = Duration::from_secs(24 * 3600); pub struct HttpsConfig { @@ -189,11 +188,10 @@ async fn handle( let mut response = if proxy_to.https_target { let to_addr = format!("https://{}", proxy_to.target_addr); - handle_timeout_and_error(reverse_proxy::call_https(remote_addr.ip(), &to_addr, req)) - .await + handle_error(reverse_proxy::call_https(remote_addr.ip(), &to_addr, req).await) } else { let to_addr = format!("http://{}", proxy_to.target_addr); - handle_timeout_and_error(reverse_proxy::call(remote_addr.ip(), &to_addr, req)).await + handle_error(reverse_proxy::call(remote_addr.ip(), &to_addr, req).await) }; // Do further processing (compression, additionnal headers) only for 2xx responses @@ -225,27 +223,14 @@ async fn handle( } } -async fn handle_timeout_and_error( - fut: impl Future<Output = Result<Response<Body>>>, -) -> Response<Body> { - select!( - resp = fut => { - match resp { - Ok(resp) => resp, - Err(e) => - Response::builder() - .status(StatusCode::BAD_GATEWAY) - .body(Body::from(format!("Proxy error: {}", e))) - .unwrap(), - } - } - _ = tokio::time::sleep(PROXY_TIMEOUT) => { - Response::builder() - .status(StatusCode::BAD_GATEWAY) - .body(Body::from("Proxy timeout")) - .unwrap() - } - ) +fn handle_error(resp: Result<Response<Body>>) -> Response<Body> { + match resp { + Ok(resp) => resp, + Err(e) => Response::builder() + .status(StatusCode::BAD_GATEWAY) + .body(Body::from(format!("Proxy error: {}", e))) + .unwrap(), + } } async fn try_compress( |