diff options
author | Shav Kinderlehrer <[email protected]> | 2024-04-07 14:44:03 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2024-04-07 14:44:03 -0400 |
commit | 1075ab0ed187a10f2eb3faf1247da8661531bbdb (patch) | |
tree | f600db86af21a63da67114a30c9825fd0ea75971 /src/get.rs | |
parent | a29d68aed7a1fbfbeb3d60df55f28fdee9fb9ca1 (diff) | |
download | chela-1075ab0ed187a10f2eb3faf1247da8661531bbdb.tar.gz chela-1075ab0ed187a10f2eb3faf1247da8661531bbdb.zip |
Add proxy support
Diffstat (limited to 'src/get.rs')
-rw-r--r-- | src/get.rs | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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()); } } |