diff --git a/src/main.rs b/src/main.rs index 20fdcdd..0522792 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,20 +36,20 @@ async fn word() -> String { async fn log_ip(req: Request, next: Next) -> Response { let ip = req - .extensions() - .get::() - .map(|addr| addr.ip().to_string()) - .or_else(|| { - req.headers() - .get("x-forwarded-for") - .and_then(|hv| hv.to_str().ok().map(String::from)) - }) + .headers() + .get("x-forwarded-for") + .and_then(|hv| hv.to_str().ok()) .or_else(|| { req.headers() .get("x-real-ip") - .and_then(|hv| hv.to_str().ok().map(String::from)) + .and_then(|hv| hv.to_str().ok()) }) - .unwrap_or_else(|| "Unknown".to_string()); + .or_else(|| { + req.headers() + .get("cf-connecting-ip") + .and_then(|hv| hv.to_str().ok()) + }) + .unwrap_or("Unknown"); info!(PATH = req.uri().path().to_string(), IP = ip);