From f622f47550fcb9de9861881ef3e11aae093a4692 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sun, 26 Mar 2023 11:42:18 +0530 Subject: [PATCH] feat: use public_url in USER_AGENT --- src/ctx.rs | 15 +++++++++------ src/introduce.rs | 3 +-- src/main.rs | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ctx.rs b/src/ctx.rs index 47d8d88..25c39d1 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -19,16 +19,12 @@ use std::sync::Arc; use std::time::Duration; use actix::dev::*; -use lazy_static::lazy_static; use reqwest::{Client, ClientBuilder}; use crate::master::Master; use crate::settings::Settings; -use crate::{DOMAIN, PKG_NAME, VERSION}; +use crate::{PKG_NAME, VERSION}; -lazy_static! { - pub static ref USER_AGENT: String = format!("{VERSION}---{PKG_NAME}---{DOMAIN}"); -} /// in seconds const CLIENT_TIMEOUT: u64 = 60; @@ -41,9 +37,16 @@ pub struct Ctx { impl Ctx { pub async fn new(settings: Settings) -> Arc { + let host = settings.introducer.public_url.host_str().unwrap(); + let host = if let Some(port) = settings.introducer.public_url.port() { + format!("{host}:{port}") + } else { + host.to_owned() + }; + let ua = format!("{VERSION}---{PKG_NAME}---{host}"); let timeout = Duration::new(CLIENT_TIMEOUT, 0); let client = ClientBuilder::new() - .user_agent(&*USER_AGENT) + .user_agent(&*ua) .use_rustls_tls() .timeout(timeout) .connect_timeout(timeout) diff --git a/src/introduce.rs b/src/introduce.rs index 38da464..de167f5 100644 --- a/src/introduce.rs +++ b/src/introduce.rs @@ -18,8 +18,7 @@ use std::collections::HashSet; use std::future::Future; -use actix::clock::sleep; -use actix_web::web::{self, Data}; +use actix_web::web; use actix_web::{HttpResponse, Responder}; use actix_web_codegen_const_routes::get; use actix_web_codegen_const_routes::post; diff --git a/src/main.rs b/src/main.rs index cf268b6..5dde6b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,6 @@ pub const CACHE_AGE: u32 = 60 * 60 * 24 * 30; // one month, I think? pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const PKG_NAME: &str = env!("CARGO_PKG_NAME"); pub const GIT_COMMIT_HASH: &str = env!("GIT_HASH"); -pub const DOMAIN: &str = "developer-starchart.forgeflux.org"; pub type ArcCtx = Arc; pub type WebCtx = Data;