aboutsummaryrefslogtreecommitdiff
path: root/src/get.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/get.rs')
-rw-r--r--src/get.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/get.rs b/src/get.rs
index 49868a8..e6b7426 100644
--- a/src/get.rs
+++ b/src/get.rs
@@ -43,7 +43,10 @@ pub async fn id(
Path(id): Path<String>,
) -> impl IntoResponse {
let mut show_request = false;
- log!("Request for '{}' from {}", id.clone(), addr.ip());
+ let ip = get_ip(headers.clone(), addr, state.clone())
+ .await
+ .unwrap_or_default();
+ log!("Request for '{}' from {}", id.clone(), ip);
let mut use_id = id;
if use_id.ends_with('+') {
show_request = true;
@@ -93,20 +96,7 @@ pub async fn id(
async fn save_analytics(headers: HeaderMap, item: UrlRow, addr: SocketAddr, state: ServerState) {
let id = item.id;
- 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 ip = get_ip(headers.clone(), addr, state.clone()).await;
let referer = match headers.get("referer") {
Some(it) => {
if let Ok(i) = it.to_str() {
@@ -146,6 +136,23 @@ VALUES ($1,$2,$3,$4)
}
}
+async fn get_ip(headers: HeaderMap, addr: SocketAddr, state: ServerState) -> 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())
+ }
+}
+
pub async fn create_id(Extension(state): Extension<ServerState>) -> Html<String> {
Html(format!(
r#"