From b0d1402431960b3d5a4e08311b782952de972097 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 16 Feb 2023 21:44:00 +0100 Subject: [PATCH] use hostname instead of internal IP --- src/routes/agreements.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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()