From eea9203dc1a7b248151af38e78af4e96f739e9a1 Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Thu, 30 Apr 2026 09:41:56 +0200 Subject: [PATCH] Replaced `STALWART_HTTPS_PORT` with `STALWART_PUBLIC_URL` --- CHANGELOG.md | 2 ++ crates/common/src/config/network.rs | 4 ++-- crates/store/src/build/registry.rs | 10 ++++---- crates/store/src/lib.rs | 2 +- crates/store/src/registry/local.rs | 36 ++++++++++++++++++----------- tests/src/utils/server.rs | 2 +- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a7b7eca..4d9b2583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,12 @@ If you are upgrading from v0.16.x, replace the binary (or run `docker pull`). If ## Added ## Changed +- Replaced `STALWART_HTTPS_PORT` with `STALWART_PUBLIC_URL`. ## Fixed - Directory: Invalidate caches when group memberships change on an external directory. - Log viewer: All events show as `INFO`. +- Registry: Allow changing object variants. - Node id renewal. ## [0.16.2] - 2026-04-28 diff --git a/crates/common/src/config/network.rs b/crates/common/src/config/network.rs index 06e4051e..b945f0c5 100644 --- a/crates/common/src/config/network.rs +++ b/crates/common/src/config/network.rs @@ -434,8 +434,8 @@ impl Http { Http { url_https: if !bp.registry.is_recovery_mode() { - if let Some(port) = bp.registry.https_port() { - format!("https://{server_name}:{port}") + if let Some(url) = bp.registry.public_url() { + url.to_string() } else { format!("https://{server_name}") } diff --git a/crates/store/src/build/registry.rs b/crates/store/src/build/registry.rs index 828dd27c..2fa873f9 100644 --- a/crates/store/src/build/registry.rs +++ b/crates/store/src/build/registry.rs @@ -274,8 +274,8 @@ impl RegistryStore { } #[inline(always)] - pub fn https_port(&self) -> Option { - self.0.env_https_port + pub fn public_url(&self) -> Option<&str> { + self.0.env_public_url.as_deref() } #[inline(always)] @@ -305,9 +305,9 @@ impl RegistryStore { } #[cfg(feature = "test_mode")] - pub fn clone_with_port(&self, store: u16) -> Self { + pub fn clone_with_public_url(&self, url: String) -> Self { let mut inner = self.0.as_ref().clone(); - inner.env_https_port = Some(store); + inner.env_public_url = Some(url); Self(inner.into()) } @@ -328,7 +328,7 @@ impl RegistryStore { env_cluster_role: cluster_role, env_push_shard_id: push_shard_id, env_hostname: hostname, - env_https_port: None, + env_public_url: None, id_generator: utils::snowflake::SnowflakeIdGenerator::new(), }) .await diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index 2a909fde..dcbfa6fd 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -217,7 +217,7 @@ pub struct RegistryStoreInner { pub(crate) env_cluster_role: Option, pub(crate) env_push_shard_id: u32, pub(crate) env_hostname: String, - pub(crate) env_https_port: Option, + pub(crate) env_public_url: Option, pub(crate) id_generator: SnowflakeIdGenerator, } diff --git a/crates/store/src/registry/local.rs b/crates/store/src/registry/local.rs index a8123d1a..85d091a5 100644 --- a/crates/store/src/registry/local.rs +++ b/crates/store/src/registry/local.rs @@ -17,6 +17,19 @@ pub(crate) enum RegistryInit { impl RegistryStoreInner { pub(crate) fn new(local_path: PathBuf) -> Self { + let env_hostname = std::env::var("STALWART_HOSTNAME") + .ok() + .filter(|h| !h.is_empty()) + .unwrap_or_else(|| { + let host = gethostname::gethostname(); + let host = host.to_string_lossy(); + if host.parse::().is_err() { + host.to_lowercase() + } else { + "localhost".to_string() + } + }); + Self { local_path, store: Store::None, @@ -40,21 +53,18 @@ impl RegistryStoreInner { .ok() .and_then(|id| id.parse::().ok().and_then(|v| v.checked_sub(1))) .unwrap_or(0), - env_hostname: std::env::var("STALWART_HOSTNAME") + env_public_url: std::env::var("STALWART_PUBLIC_URL") .ok() - .filter(|h| !h.is_empty()) - .unwrap_or_else(|| { - let host = gethostname::gethostname(); - let host = host.to_string_lossy(); - if host.parse::().is_err() { - host.to_lowercase() - } else { - "localhost".to_string() - } + .map(|v| v.trim().trim_end_matches('/').to_string()) + .filter(|u| !u.is_empty()) + .or_else(|| { + std::env::var("STALWART_HTTPS_PORT").ok().and_then(|p| { + p.parse::() + .ok() + .map(|port| format!("https://{}:{}", env_hostname, port)) + }) }), - env_https_port: std::env::var("STALWART_HTTPS_PORT") - .ok() - .and_then(|p| p.parse::().ok()), + env_hostname, } } diff --git a/tests/src/utils/server.rs b/tests/src/utils/server.rs index 69cf5492..81d117b3 100644 --- a/tests/src/utils/server.rs +++ b/tests/src/utils/server.rs @@ -317,7 +317,7 @@ impl TestServerBuilder { self.bootstrap.registry = self .bootstrap .registry - .clone_with_port(self.http_listener_port); + .clone_with_public_url(format!("https://127.0.0.1:{}", self.http_listener_port)); if init_store { // Add safe defaults if missing