mirror of
https://github.com/warp-tech/warpgate.git
synced 2024-09-20 06:46:17 +08:00
fixed test
This commit is contained in:
parent
0ddc7979ea
commit
ea07658f0b
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue