aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Davies <jpds@protonmail.com>2023-02-09 13:49:43 +0000
committerJonathan Davies <jpds@protonmail.com>2023-03-06 11:43:35 +0000
commite4e5196066a75ed9327a62d8082decb1e0c381e7 (patch)
tree9c92850e4a70577b251431540c1712db759ce6e5
parentff70e09aa090a140729483783076e7938fad0d39 (diff)
downloadgarage-e4e5196066a75ed9327a62d8082decb1e0c381e7.tar.gz
garage-e4e5196066a75ed9327a62d8082decb1e0c381e7.zip
api/generic_server.rs: Use new handle_forwarded_for_headers() function.
-rw-r--r--src/api/generic_server.rs13
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,