diff --git a/src/proxy/handler.rs b/src/proxy/handler.rs index 8a771cc..a1cf1d7 100644 --- a/src/proxy/handler.rs +++ b/src/proxy/handler.rs @@ -121,6 +121,7 @@ pub async fn proxy( mut req: Request, client: Client, Incoming>, config: Arc, + remote_addr: std::net::SocketAddr, ) -> Result, Error> { // Get path from URI (using String to avoid borrow conflict with mutable req) let path = req.uri().path().to_string(); @@ -225,11 +226,11 @@ pub async fn proxy( _ => {} // ignore unknown schemes } - // X-Forwarded-For: client IP address - // TODO: Extract real client IP from connection info - // For now, we can use the original host as a placeholder - if let Some(for_value) = original_host_header { - req.headers_mut().insert("X-Forwarded-For", for_value); + // X-Forwarded-For: real client IP from TCP connection + if let Ok(ip_value) = + hyper::header::HeaderValue::from_str(&remote_addr.ip().to_string()) + { + req.headers_mut().insert("X-Forwarded-For", ip_value); } // Remove hop-by-hop headers from request before sending to backend diff --git a/src/proxy/proxy.rs b/src/proxy/proxy.rs index 86d5908..e4bb65f 100644 --- a/src/proxy/proxy.rs +++ b/src/proxy/proxy.rs @@ -152,7 +152,7 @@ impl Proxy { ); loop { - let (stream, _) = listener.accept().await?; + let (stream, remote_addr) = listener.accept().await?; let io = TokioIo::new(stream); let client = self.client.clone(); let config = Arc::new(self.config.clone()); @@ -165,7 +165,7 @@ impl Proxy { let service = service_fn(move |req| { let client = client.clone(); let config = config.clone(); - proxy(req, client, config) + proxy(req, client, config, remote_addr) }); let mut builder = hyper::server::conn::http1::Builder::new();