feat: pass x-forwarded-for

This commit is contained in:
Kieran 2024-09-27 16:26:38 +01:00
parent aaad974d8f
commit c47432e58f
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941

View File

@ -14,6 +14,8 @@ struct Event {
pub referrer: Option<String>, pub referrer: Option<String>,
#[serde(skip_serializing)] #[serde(skip_serializing)]
pub user_agent: Option<String>, pub user_agent: Option<String>,
#[serde(skip_serializing)]
pub xff: Option<String>,
} }
pub struct PlausibleAnalytics { pub struct PlausibleAnalytics {
@ -39,6 +41,13 @@ impl PlausibleAnalytics {
None => "", None => "",
}, },
) )
.set(
"x-forwarded-for",
match &msg.xff {
Some(s) => s,
None => "",
},
)
.send_json(&msg) .send_json(&msg)
{ {
Ok(v) => info!("Sent {:?}", msg), Ok(v) => info!("Sent {:?}", msg),
@ -68,6 +77,10 @@ impl Analytics for PlausibleAnalytics {
Some(s) => Some(s.to_string()), Some(s) => Some(s.to_string()),
None => None, None => None,
}, },
xff: match req.headers().get_one("X-Forwarded-For") {
Some(s) => Some(s.to_string()),
None => None,
}
})?) })?)
} }
} }