From 8d47bef9d45a767fcc166d26b75fc51937116bcd Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 8 Dec 2021 17:27:27 +0100 Subject: Fix path prefixes --- src/proxy_config.rs | 2 +- src/reverse_proxy.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/proxy_config.rs b/src/proxy_config.rs index a15c143..29493b2 100644 --- a/src/proxy_config.rs +++ b/src/proxy_config.rs @@ -99,7 +99,7 @@ fn parse_tricot_tag( } let (host, path_prefix) = match splits[1].split_once('/') { - Some((h, p)) => (h, Some(p.to_string())), + Some((h, p)) => (h, Some(format!("/{}", p))), None => (splits[1], None), }; diff --git a/src/reverse_proxy.rs b/src/reverse_proxy.rs index 3d2a1fc..1768724 100644 --- a/src/reverse_proxy.rs +++ b/src/reverse_proxy.rs @@ -72,10 +72,9 @@ fn create_proxied_request( *builder.headers_mut().unwrap() = remove_hop_headers(request.headers()); - let host_header_name = "host"; - let x_forwarded_for_header_name = "x-forwarded-for"; // If request does not have host header, add it from original URI authority + let host_header_name = "host"; if let Some(authority) = request.uri().authority() { if let hyper::header::Entry::Vacant(entry) = builder.headers_mut().unwrap().entry(host_header_name) @@ -85,6 +84,7 @@ fn create_proxied_request( } // Add forwarding information in the headers + let x_forwarded_for_header_name = "x-forwarded-for"; match builder .headers_mut() .unwrap() @@ -100,6 +100,8 @@ fn create_proxied_request( } } + builder.headers_mut().unwrap().insert(HeaderName::from_bytes(b"x-forwarded-proto")?, "https".try_into()?); + if let Some(conn) = request.headers().get("connection") { if conn.to_str()?.to_lowercase() == "upgrade" { if let Some(upgrade) = request.headers().get("upgrade") { -- cgit v1.2.3