fixed test

This commit is contained in:
Eugene 2024-02-04 21:09:26 +01:00
parent 0ddc7979ea
commit ea07658f0b
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4

View file

@ -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<String> { pub async fn get_client_ip(req: &Request) -> poem::Result<String> {
let services: Data<&Services> = <_>::from_request_without_body(&req).await?; let services: Option<Data<&Services>> = <_>::from_request_without_body(&req).await.ok();
let config = services.config.lock().await; 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 let remote_ip = req
.remote_addr() .remote_addr()
@ -44,7 +49,7 @@ pub async fn get_client_ip(req: &Request) -> poem::Result<String> {
.map(|x| x.ip().to_string()) .map(|x| x.ip().to_string())
.unwrap_or("<unknown>".into()); .unwrap_or("<unknown>".into());
match config.store.http.trust_x_forwarded_headers { match trust_x_forwarded_headers {
true => Ok(req true => Ok(req
.header("x-forwarded-for") .header("x-forwarded-for")
.map(|x| x.to_string()) .map(|x| x.to_string())