forked from Deuxfleurs/garage
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: Deuxfleurs/garage#500
This commit is contained in:
commit
8b4d0adc75
1 changed files with 20 additions and 1 deletions
|
@ -125,7 +125,26 @@ impl<A: ApiHandler> ApiServer<A> {
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
) -> Result<Response<Body>, GarageError> {
|
) -> Result<Response<Body>, GarageError> {
|
||||||
let uri = req.uri().clone();
|
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();
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"{} (via {}) {} {}",
|
||||||
|
forwarded_for_ip_addr,
|
||||||
|
addr,
|
||||||
|
req.method(),
|
||||||
|
uri
|
||||||
|
);
|
||||||
|
} else {
|
||||||
info!("{} {} {}", addr, req.method(), uri);
|
info!("{} {} {}", addr, req.method(), uri);
|
||||||
|
}
|
||||||
debug!("{:?}", req);
|
debug!("{:?}", req);
|
||||||
|
|
||||||
let tracer = opentelemetry::global::tracer("garage");
|
let tracer = opentelemetry::global::tracer("garage");
|
||||||
|
|
Loading…
Reference in a new issue