mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 08:25:16 +00:00
Check for upstream proxy
This commit is contained in:
@ -194,7 +194,28 @@ impl HttpRequestHandler {
|
||||
|
||||
/// Get the remote IP address
|
||||
pub fn remote_ip(&self) -> String {
|
||||
self.request.peer_addr().unwrap().ip().to_string()
|
||||
let mut ip = self.request.peer_addr().unwrap().ip().to_string();
|
||||
|
||||
// We check if the request comes from a trusted reverse proxy
|
||||
if let Some(proxy) = conf().proxy.as_ref() {
|
||||
if ip.eq(proxy) {
|
||||
if let Some(header) = self.request.headers().get("X-Forwarded-For") {
|
||||
let header: Vec<String> = header
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.split(",")
|
||||
.map(|f| f.to_string())
|
||||
.collect();
|
||||
|
||||
if header.len() > 0 {
|
||||
ip = header[0].to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ip
|
||||
}
|
||||
|
||||
/// Check if a POST parameter was present in the request or not
|
||||
|
Reference in New Issue
Block a user