aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/get.rs16
3 files changed, 17 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 15a7252..dd371e4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -194,7 +194,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chela"
-version = "1.1.0"
+version = "1.2.0"
dependencies = [
"axum",
"color-eyre",
diff --git a/Cargo.toml b/Cargo.toml
index 7f8867f..9e5ef6e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "chela"
-version = "1.1.0"
+version = "1.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/get.rs b/src/get.rs
index efe2711..a00ac48 100644
--- a/src/get.rs
+++ b/src/get.rs
@@ -41,7 +41,21 @@ pub async fn id_unix(
Extension(state): Extension<ServerState>,
Path(id): Path<String>,
) -> 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
}