web_server.rs: Log X-Forwarded-For IP #504
1 changed files with 14 additions and 1 deletions
|
@ -29,6 +29,7 @@ use garage_model::garage::Garage;
|
||||||
|
|
||||||
use garage_table::*;
|
use garage_table::*;
|
||||||
use garage_util::error::Error as GarageError;
|
use garage_util::error::Error as GarageError;
|
||||||
|
use garage_util::forwarded_headers;
|
||||||
use garage_util::metrics::{gen_trace_id, RecordDuration};
|
use garage_util::metrics::{gen_trace_id, RecordDuration};
|
||||||
|
|
||||||
struct WebMetrics {
|
struct WebMetrics {
|
||||||
|
@ -104,7 +105,19 @@ impl WebServer {
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
) -> Result<Response<Body>, Infallible> {
|
) -> Result<Response<Body>, Infallible> {
|
||||||
|
if let Ok(forwarded_for_ip_addr) =
|
||||||
|
forwarded_headers::handle_forwarded_for_headers(&req.headers())
|
||||||
|
|||||||
|
{
|
||||||
|
info!(
|
||||||
jpds marked this conversation as resolved
Outdated
lx
commented
Same as above, lines 108-111 should be rewritten as:
Same as above, lines 108-111 should be rewritten as:
```rust
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());
|
info!("{} {} {}", addr, req.method(), req.uri());
|
||||||
|
}
|
||||||
|
|
||||||
// Lots of instrumentation
|
// Lots of instrumentation
|
||||||
let tracer = opentelemetry::global::tracer("garage");
|
let tracer = opentelemetry::global::tracer("garage");
|
||||||
|
|
Loading…
Reference in a new issue
Same here