diff --git a/src/routes/agreements.rs b/src/routes/agreements.rs index 30452b7..4169ac7 100644 --- a/src/routes/agreements.rs +++ b/src/routes/agreements.rs @@ -1,6 +1,5 @@ -use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder}; +use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder}; use askama::Template; -use std::net::SocketAddr; use crate::config::Config; @@ -8,7 +7,10 @@ use crate::config::Config; #[get("/.well-known/security.txt")] #[get("/security.txt")] pub async fn security(req: HttpRequest, config: web::Data) -> impl Responder { - HttpResponse::Ok().body(get_security(config.get_ref().clone(), req.peer_addr())) + HttpResponse::Ok().body(get_security( + config.get_ref().clone(), + req.connection_info().to_owned(), + )) } #[derive(Template)] @@ -19,11 +21,11 @@ struct SecurityTemplate { url: String, } -fn get_security(config: Config, addr: Option) -> String { +fn get_security(config: Config, info: ConnectionInfo) -> String { let data = SecurityTemplate { contact: config.mail.unwrap_or_default(), pref_lang: config.lang.unwrap_or_default(), - url: format!("{}/.well-known/security.txt", addr.unwrap().ip()), + url: format!("{}/.well-known/security.txt", info.host()), }; data.render().unwrap()