aboutsummaryrefslogtreecommitdiff
path: root/src/get.rs
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-04-07 14:44:03 -0400
committerShav Kinderlehrer <[email protected]>2024-04-07 14:44:03 -0400
commit1075ab0ed187a10f2eb3faf1247da8661531bbdb (patch)
treef600db86af21a63da67114a30c9825fd0ea75971 /src/get.rs
parenta29d68aed7a1fbfbeb3d60df55f28fdee9fb9ca1 (diff)
downloadchela-1075ab0ed187a10f2eb3faf1247da8661531bbdb.tar.gz
chela-1075ab0ed187a10f2eb3faf1247da8661531bbdb.zip
Add proxy support
Diffstat (limited to 'src/get.rs')
-rw-r--r--src/get.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/get.rs b/src/get.rs
index d96e05f..49868a8 100644
--- a/src/get.rs
+++ b/src/get.rs
@@ -93,7 +93,20 @@ pub async fn id(
async fn save_analytics(headers: HeaderMap, item: UrlRow, addr: SocketAddr, state: ServerState) {
let id = item.id;
- let ip = addr.ip().to_string();
+ let ip: Option<String> = 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(addr.ip().to_string())
+ };
let referer = match headers.get("referer") {
Some(it) => {
if let Ok(i) = it.to_str() {
@@ -129,7 +142,7 @@ VALUES ($1,$2,$3,$4)
.await;
if res.is_ok() {
- log!("Saved analytics for '{id}' from {ip}");
+ log!("Saved analytics for '{id}' from {}", ip.unwrap_or_default());
}
}