diff options
Diffstat (limited to 'src/https.rs')
-rw-r--r-- | src/https.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/https.rs b/src/https.rs index e1db42e..b0d452b 100644 --- a/src/https.rs +++ b/src/https.rs @@ -79,6 +79,9 @@ async fn handle( req: Request<Body>, proxy_config: Arc<ProxyConfig>, ) -> Result<Response<Body>, anyhow::Error> { + let method = req.method().clone(); + let uri = req.uri().to_string(); + let host = if let Some(auth) = req.uri().authority() { auth.as_str() } else { @@ -89,7 +92,7 @@ async fn handle( }; let path = req.uri().path(); - let ent = proxy_config + let best_match = proxy_config .entries .iter() .filter(|ent| { @@ -111,17 +114,20 @@ async fn handle( ) }); - if let Some(proxy_to) = ent { - proxy_to.calls.fetch_add(1, Ordering::SeqCst); - let to_addr = format!("http://{}", proxy_to.target_addr); - let method = req.method().clone(); + if let Some(proxy_to) = best_match { + proxy_to.calls.fetch_add(1, Ordering::SeqCst); - let uri = req.uri().to_string(); debug!("{}{} -> {}", host, path, proxy_to); trace!("Request: {:?}", req); - let mut response = reverse_proxy::call(remote_addr.ip(), &to_addr, req).await?; + let mut response = if proxy_to.https_target { + let to_addr = format!("https://{}", proxy_to.target_addr); + reverse_proxy::call_https(remote_addr.ip(), &to_addr, req).await? + } else { + let to_addr = format!("http://{}", proxy_to.target_addr); + reverse_proxy::call(remote_addr.ip(), &to_addr, req).await? + }; for (header, value) in proxy_to.add_headers.iter() { response.headers_mut().insert( @@ -134,7 +140,8 @@ async fn handle( Ok(response) } else { - info!("Proxying {} {} -> NOT FOUND", host, path); + debug!("{}{} -> NOT FOUND", host, path); + info!("{} 404 {}", method, uri); Ok(Response::builder() .status(StatusCode::NOT_FOUND) |