diff options
author | Alex <alex@adnab.me> | 2023-02-06 14:20:12 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-02-06 14:20:12 +0000 |
commit | 8b4d0adc75acb2dd4d13c819cb9d23eacb045f2d (patch) | |
tree | 0cd704affcd344a9623a80a8fab145ed6e8144b4 /src | |
parent | c2a9f00a58c78ce9766e21c8a676d458e7763004 (diff) | |
parent | 94d70bec6962046377519521bd53dfcac37e3c3b (diff) | |
download | garage-8b4d0adc75acb2dd4d13c819cb9d23eacb045f2d.tar.gz garage-8b4d0adc75acb2dd4d13c819cb9d23eacb045f2d.zip |
Merge pull request 'generic_server.rs: Added support for logging X-Forwarded-For header.' (#500) from jpds/garage:generic_server-log-x-forwarded-for into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/500
Diffstat (limited to 'src')
-rw-r--r-- | src/api/generic_server.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/api/generic_server.rs b/src/api/generic_server.rs index 62fe4e5a..aa90868a 100644 --- a/src/api/generic_server.rs +++ b/src/api/generic_server.rs @@ -125,7 +125,26 @@ impl<A: ApiHandler> ApiServer<A> { addr: SocketAddr, ) -> Result<Response<Body>, GarageError> { let uri = req.uri().clone(); - info!("{} {} {}", addr, req.method(), uri); + + let has_forwarded_for_header = req.headers().contains_key("x-forwarded-for"); + if has_forwarded_for_header { + let forwarded_for_ip_addr = &req + .headers() + .get("x-forwarded-for") + .expect("Could not parse X-Forwarded-For header") + .to_str() + .unwrap_or_default(); + + info!( + "{} (via {}) {} {}", + forwarded_for_ip_addr, + addr, + req.method(), + uri + ); + } else { + info!("{} {} {}", addr, req.method(), uri); + } debug!("{:?}", req); let tracer = opentelemetry::global::tracer("garage"); |