fix: removes 'x-forwarded-for' and adds other client ip headers for reference
This commit is contained in:
parent
9d7a931045
commit
6f61bda344
14
src/main.rs
14
src/main.rs
@ -34,11 +34,15 @@ async fn word() -> String {
|
||||
}
|
||||
|
||||
async fn log_ip(req: Request<Body>, next: Next) -> Response {
|
||||
let mut head = "x-forwarded-for";
|
||||
let mut head = "REMOTE_ADDR";
|
||||
let ip = req
|
||||
.headers()
|
||||
.get(head)
|
||||
.and_then(|hv| hv.to_str().ok())
|
||||
.or_else(|| {
|
||||
head = "HTTP_CLIENT_IP";
|
||||
req.headers().get(head).and_then(|hv| hv.to_str().ok())
|
||||
})
|
||||
.or_else(|| {
|
||||
head = "x-real-ip";
|
||||
req.headers().get(head).and_then(|hv| hv.to_str().ok())
|
||||
@ -47,6 +51,14 @@ async fn log_ip(req: Request<Body>, next: Next) -> Response {
|
||||
head = "cf-connection-ip";
|
||||
req.headers().get(head).and_then(|hv| hv.to_str().ok())
|
||||
})
|
||||
.or_else(|| {
|
||||
head = "HTTP_X_FORWARDED_FOR";
|
||||
req.headers().get(head).and_then(|hv| hv.to_str().ok())
|
||||
})
|
||||
.or_else(|| {
|
||||
head = "HTTP_FORWARDED_FOR";
|
||||
req.headers().get(head).and_then(|hv| hv.to_str().ok())
|
||||
})
|
||||
.unwrap_or("Unknown");
|
||||
|
||||
if format!("{ip}") == "Unknown" {
|
||||
|
Loading…
x
Reference in New Issue
Block a user