From 6e3407b99c76f5e63f923a76fbafd34610483ae1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 28 Apr 2024 23:51:13 +0200 Subject: x-real-ip --- readme.md | 6 +++--- src/filters/proxy.rs | 16 ++-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/readme.md b/readme.md index 2194d81..3f30b9c 100644 --- a/readme.md +++ b/readme.md @@ -60,9 +60,9 @@ hosts: ### Filters - **filter `proxy`** - - Forwards the request as-is to some other server. `x-forwarded-proto` and - `x-forwarded-for` headers are injected into the request. Connection upgrades - are handled by direct forwarding of network traffic. + - Forwards the request as-is to some other server. the `x-real-ip` header is + injected into the request. Connection upgrades are handled by direct + forwarding of network traffic. - `backend`: socket address (string) to the backend server - **filter `files`** - Provides a simple built-in fileserver. The server handles `accept-ranges`. diff --git a/src/filters/proxy.rs b/src/filters/proxy.rs index 0e1a556..7cfc643 100644 --- a/src/filters/proxy.rs +++ b/src/filters/proxy.rs @@ -3,10 +3,7 @@ use http_body_util::{combinators::BoxBody, BodyExt}; use hyper::{ body::Incoming, header::UPGRADE, - http::{ - uri::{PathAndQuery, Scheme}, - HeaderValue, - }, + http::{uri::PathAndQuery, HeaderValue}, upgrade::OnUpgrade, Request, Uri, }; @@ -23,7 +20,6 @@ pub async fn proxy_request( #[cfg(feature = "mond")] state.reporting.request_out.inc(); - let scheme_secure = req.uri().scheme() == Some(&Scheme::HTTPS); *req.uri_mut() = Uri::builder() .path_and_query( req.uri() @@ -36,17 +32,9 @@ pub async fn proxy_request( .unwrap(); req.headers_mut().insert( - "x-forwarded-for", + "x-real-ip", HeaderValue::from_str(&format!("{addr}")).unwrap(), ); - req.headers_mut().insert( - "x-forwarded-proto", - if scheme_secure { - HeaderValue::from_static("https") - } else { - HeaderValue::from_static("http") - }, - ); let do_upgrade = req.headers().contains_key(UPGRADE); let on_upgrade_downstream = req.extensions_mut().remove::(); -- cgit v1.2.3-70-g09d2