aboutsummaryrefslogtreecommitdiff
path: root/src/reverse_proxy.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-24 20:55:26 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-24 20:55:26 +0100
commitea050c7045764f69a6dd25a2b0c75186dddfc50e (patch)
tree595ab80389b62f3a7f797d4e6e710fa09bfe8f4f /src/reverse_proxy.rs
parent7d5070c57dabfb22c5bd17a850adcbbfa19d730a (diff)
downloadtricot-ea050c7045764f69a6dd25a2b0c75186dddfc50e.tar.gz
tricot-ea050c7045764f69a6dd25a2b0c75186dddfc50e.zip
Actually that was quite a stupid way of handling timeoutsdocker-33
Diffstat (limited to 'src/reverse_proxy.rs')
-rw-r--r--src/reverse_proxy.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/reverse_proxy.rs b/src/reverse_proxy.rs
index f4ded40..6ea15a0 100644
--- a/src/reverse_proxy.rs
+++ b/src/reverse_proxy.rs
@@ -5,19 +5,21 @@ use std::convert::TryInto;
use std::net::IpAddr;
use std::str::FromStr;
use std::sync::Arc;
-use std::time::SystemTime;
+use std::time::{Duration, SystemTime};
use anyhow::Result;
use log::*;
use http::header::HeaderName;
use hyper::header::{HeaderMap, HeaderValue};
-use hyper::{header, Body, Client, Request, Response, Uri};
+use hyper::{client::HttpConnector, header, Body, Client, Request, Response, Uri};
use rustls::client::{ServerCertVerified, ServerCertVerifier};
use rustls::{Certificate, ServerName};
use crate::tls_util::HttpsConnectorFixedDnsname;
+pub const PROXY_TIMEOUT: Duration = Duration::from_secs(60);
+
const HOP_HEADERS: &[HeaderName] = &[
header::CONNECTION,
//header::KEEP_ALIVE,
@@ -128,7 +130,11 @@ pub async fn call(
trace!("Proxied request: {:?}", proxied_request);
- let client = Client::new();
+ let mut connector = HttpConnector::new();
+ connector.set_connect_timeout(Some(PROXY_TIMEOUT));
+
+ let client: Client<_, hyper::Body> = Client::builder().build(connector);
+
let response = client.request(proxied_request).await?;
trace!("Inner response: {:?}", response);
@@ -150,7 +156,11 @@ pub async fn call_https(
.with_safe_defaults()
.with_custom_certificate_verifier(Arc::new(DontVerifyServerCert))
.with_no_client_auth();
- let connector = HttpsConnectorFixedDnsname::new(tls_config, "dummy");
+
+ let mut http_connector = HttpConnector::new();
+ http_connector.set_connect_timeout(Some(PROXY_TIMEOUT));
+ let connector = HttpsConnectorFixedDnsname::new(tls_config, "dummy", http_connector);
+
let client: Client<_, hyper::Body> = Client::builder().build(connector);
let response = client.request(proxied_request).await?;