diff options
author | Alex Auvolat <alex@adnab.me> | 2022-01-24 20:55:26 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-24 20:55:26 +0100 |
commit | ea050c7045764f69a6dd25a2b0c75186dddfc50e (patch) | |
tree | 595ab80389b62f3a7f797d4e6e710fa09bfe8f4f /src/https.rs | |
parent | 7d5070c57dabfb22c5bd17a850adcbbfa19d730a (diff) | |
download | tricot-ea050c7045764f69a6dd25a2b0c75186dddfc50e.tar.gz tricot-ea050c7045764f69a6dd25a2b0c75186dddfc50e.zip |
Actually that was quite a stupid way of handling timeoutsdocker-33
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( |