Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Feb 4, 2024
1 parent 0ddc797 commit ea07658
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions warpgate-protocol-http/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ pub fn log_request_result(method: &Method, url: &Uri, client_ip: String, status:
}

pub async fn get_client_ip(req: &Request) -> poem::Result<String> {
let services: Data<&Services> = <_>::from_request_without_body(&req).await?;
let config = services.config.lock().await;
let services: Option<Data<&Services>> = <_>::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()
.as_socket_addr()
.map(|x| x.ip().to_string())
.unwrap_or("<unknown>".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())
Expand Down

0 comments on commit ea07658

Please sign in to comment.