Initial public release

This commit is contained in:
thakares committed 2026-06-11 20:19:03 +05:30
commit c1107147b4
92 files changed
+10562

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
use std::net::SocketAddr;
use axum::{
extract::ConnectInfo,
http::HeaderMap,
};
// Extract client IP address from proxy headers or connection info
pub fn get_client_ip(headers: &HeaderMap, connect_info: Option<ConnectInfo<SocketAddr>>) -> String {
if let Some(ip) = headers.get("cf-connecting-ip").and_then(|h| h.to_str().ok()) {
return ip.to_string();
}
if let Some(ip) = headers.get("x-real-ip").and_then(|h| h.to_str().ok()) {
return ip.to_string();
}
if let Some(ips) = headers.get("x-forwarded-for").and_then(|h| h.to_str().ok()) {
if let Some(ip) = ips.split(',').next() {
return ip.trim().to_string();
}
}
if let Some(ConnectInfo(addr)) = connect_info {
return addr.ip().to_string();
}
"127.0.0.1".to_string()
}