feat: use public_url in USER_AGENT
This commit is contained in:
parent
bbfd19d250
commit
f622f47550
3 changed files with 10 additions and 9 deletions
15
src/ctx.rs
15
src/ctx.rs
|
@ -19,16 +19,12 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use actix::dev::*;
|
use actix::dev::*;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use reqwest::{Client, ClientBuilder};
|
use reqwest::{Client, ClientBuilder};
|
||||||
|
|
||||||
use crate::master::Master;
|
use crate::master::Master;
|
||||||
use crate::settings::Settings;
|
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
|
/// in seconds
|
||||||
const CLIENT_TIMEOUT: u64 = 60;
|
const CLIENT_TIMEOUT: u64 = 60;
|
||||||
|
|
||||||
|
@ -41,9 +37,16 @@ pub struct Ctx {
|
||||||
|
|
||||||
impl Ctx {
|
impl Ctx {
|
||||||
pub async fn new(settings: Settings) -> Arc<Self> {
|
pub async fn new(settings: Settings) -> Arc<Self> {
|
||||||
|
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 timeout = Duration::new(CLIENT_TIMEOUT, 0);
|
||||||
let client = ClientBuilder::new()
|
let client = ClientBuilder::new()
|
||||||
.user_agent(&*USER_AGENT)
|
.user_agent(&*ua)
|
||||||
.use_rustls_tls()
|
.use_rustls_tls()
|
||||||
.timeout(timeout)
|
.timeout(timeout)
|
||||||
.connect_timeout(timeout)
|
.connect_timeout(timeout)
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
use actix::clock::sleep;
|
use actix_web::web;
|
||||||
use actix_web::web::{self, Data};
|
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder};
|
||||||
use actix_web_codegen_const_routes::get;
|
use actix_web_codegen_const_routes::get;
|
||||||
use actix_web_codegen_const_routes::post;
|
use actix_web_codegen_const_routes::post;
|
||||||
|
|
|
@ -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 VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
pub const GIT_COMMIT_HASH: &str = env!("GIT_HASH");
|
pub const GIT_COMMIT_HASH: &str = env!("GIT_HASH");
|
||||||
pub const DOMAIN: &str = "developer-starchart.forgeflux.org";
|
|
||||||
|
|
||||||
pub type ArcCtx = Arc<Ctx>;
|
pub type ArcCtx = Arc<Ctx>;
|
||||||
pub type WebCtx = Data<ArcCtx>;
|
pub type WebCtx = Data<ArcCtx>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue