diff options
author | Alex <alex@adnab.me> | 2023-03-06 12:33:06 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-03-06 12:33:06 +0000 |
commit | 00dcfc97a5d397120ea722b2c836fb6968e87e39 (patch) | |
tree | 06d9ec3da5b555a02c27cc58d2b94692abb1e54c /src/web/web_server.rs | |
parent | 0d0906b066eb76111f3b427dce1c50eac083366c (diff) | |
parent | 4e0fc3d6c9d764f2eecb7cf9e995580e734bdb2d (diff) | |
download | garage-00dcfc97a5d397120ea722b2c836fb6968e87e39.tar.gz garage-00dcfc97a5d397120ea722b2c836fb6968e87e39.zip |
Merge pull request 'web_server.rs: Log X-Forwarded-For IP' (#504) from jpds/garage:web_server-log-x-forwarded-for into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/504
Diffstat (limited to 'src/web/web_server.rs')
-rw-r--r-- | src/web/web_server.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs index 5719da54..0c7edf23 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -29,6 +29,7 @@ use garage_model::garage::Garage; use garage_table::*; use garage_util::error::Error as GarageError; +use garage_util::forwarded_headers; use garage_util::metrics::{gen_trace_id, RecordDuration}; struct WebMetrics { @@ -104,7 +105,19 @@ impl WebServer { req: Request<Body>, addr: SocketAddr, ) -> Result<Response<Body>, Infallible> { - info!("{} {} {}", addr, req.method(), req.uri()); + if let Ok(forwarded_for_ip_addr) = + forwarded_headers::handle_forwarded_for_headers(&req.headers()) + { + info!( + "{} (via {}) {} {}", + forwarded_for_ip_addr, + addr, + req.method(), + req.uri() + ); + } else { + info!("{} {} {}", addr, req.method(), req.uri()); + } // Lots of instrumentation let tracer = opentelemetry::global::tracer("garage"); |