aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorteutat3s <10206665+teutat3s@users.noreply.github.com>2023-03-13 13:59:42 +0100
committerteutat3s <10206665+teutat3s@users.noreply.github.com>2023-03-13 13:59:42 +0100
commit8ad6efb338bd20036614dd0697edb328aed1e7fd (patch)
treebef0b3bb43be503b5459e610f782e658562cf3bf /src/api
parent3b498c7c4725ab83edd5fdeba65b32ae6bdc3e66 (diff)
parent3325928c1327eb35201723013388ede2399f2350 (diff)
downloadgarage-8ad6efb338bd20036614dd0697edb328aed1e7fd.tar.gz
garage-8ad6efb338bd20036614dd0697edb328aed1e7fd.zip
Merge branch 'main' into pnet_datalink-0.33.0
Diffstat (limited to 'src/api')
-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,