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/api | |
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/api')
-rw-r--r-- | src/api/generic_server.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/api/generic_server.rs b/src/api/generic_server.rs index aa90868a..d0354d28 100644 --- a/src/api/generic_server.rs +++ b/src/api/generic_server.rs @@ -19,6 +19,7 @@ use opentelemetry::{ }; use garage_util::error::Error as GarageError; +use garage_util::forwarded_headers; use garage_util::metrics::{gen_trace_id, RecordDuration}; pub(crate) trait ApiEndpoint: Send + Sync + 'static { @@ -126,15 +127,9 @@ impl<A: ApiHandler> ApiServer<A> { ) -> Result<Response<Body>, GarageError> { let uri = req.uri().clone(); - 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(); - + if let Ok(forwarded_for_ip_addr) = + forwarded_headers::handle_forwarded_for_headers(&req.headers()) + { info!( "{} (via {}) {} {}", forwarded_for_ip_addr, |