From ea07658f0bc31f74ab98da379fb4315bc33b086d Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 4 Feb 2024 21:09:26 +0100 Subject: [PATCH] fixed test --- warpgate-protocol-http/src/logging.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/warpgate-protocol-http/src/logging.rs b/warpgate-protocol-http/src/logging.rs index 3d94f7c..081081d 100644 --- a/warpgate-protocol-http/src/logging.rs +++ b/warpgate-protocol-http/src/logging.rs @@ -35,8 +35,13 @@ pub fn log_request_result(method: &Method, url: &Uri, client_ip: String, status: } pub async fn get_client_ip(req: &Request) -> poem::Result { - let services: Data<&Services> = <_>::from_request_without_body(&req).await?; - let config = services.config.lock().await; + let services: Option> = <_>::from_request_without_body(&req).await.ok(); + let trust_x_forwarded_headers = if let Some(services) = services { + let config = services.config.lock().await; + config.store.http.trust_x_forwarded_headers + } else { + false + }; let remote_ip = req .remote_addr() @@ -44,7 +49,7 @@ pub async fn get_client_ip(req: &Request) -> poem::Result { .map(|x| x.ip().to_string()) .unwrap_or("".into()); - match config.store.http.trust_x_forwarded_headers { + match trust_x_forwarded_headers { true => Ok(req .header("x-forwarded-for") .map(|x| x.to_string())