Use proper IP address when behind proxy
This commit is contained in:
parent
2faf289829
commit
938be8949f
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -194,7 +194,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chela"
|
name = "chela"
|
||||||
version = "1.1.0"
|
version = "1.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "chela"
|
name = "chela"
|
||||||
version = "1.1.0"
|
version = "1.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
16
src/get.rs
16
src/get.rs
@ -41,7 +41,21 @@ pub async fn id_unix(
|
|||||||
Extension(state): Extension<ServerState>,
|
Extension(state): Extension<ServerState>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let ip = format!("{:?}", addr.peer_addr);
|
let ip = if state.behind_proxy {
|
||||||
|
match headers.get("x-real-ip") {
|
||||||
|
Some(it) => {
|
||||||
|
if let Ok(i) = it.to_str() {
|
||||||
|
Some(i.to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Some(format!("{:?}", addr.peer_addr))
|
||||||
|
}
|
||||||
|
.unwrap_or_default();
|
||||||
run_id(headers, ip, state, id).await
|
run_id(headers, ip, state, id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user