Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/proxy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub async fn proxy(
mut req: Request<Incoming>,
client: Client<HttpsConnector<HttpConnector>, Incoming>,
config: Arc<Config>,
remote_addr: std::net::SocketAddr,
) -> Result<Response<ResponseBody>, Error> {
// Get path from URI (using String to avoid borrow conflict with mutable req)
let path = req.uri().path().to_string();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand Down
Loading