pub struct Config { /* private fields */ }Expand description
Immutable runtime configuration, built once at startup.
Cloned per request by the gate middleware (from_fn_with_state
requires the state to be Clone), which is why fields stay cheap to
clone (SocketAddr is Copy; Bytes is reference-counted; Vec<Hash>
and String each clone one small heap allocation per request).
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_env() -> Result<Self, ConfigError>
pub fn from_env() -> Result<Self, ConfigError>
Build from the process environment. Delegates to the same pure
validation as Config::from_values so tests do not have to mutate
process-wide env (which is unsafe in Rust 2024).
§Errors
Returns ConfigError if MBA_ADDRESS is not a valid non-zero IP
socket address, no MBA_PASSWORD* variable has a non-empty UTF-8
value, two of them share the same value, a template-text override is
not valid Unicode, or MBA_UPSTREAM is not a valid absolute HTTP(S)
URL.
Sourcepub fn from_values(password: &str, upstream: &str) -> Result<Self, ConfigError>
pub fn from_values(password: &str, upstream: &str) -> Result<Self, ConfigError>
Build and validate from explicit values (pure, env-free).
§Examples
assert!(Config::from_values("hunter2", "http://app:2001").is_ok());
assert!(Config::from_values("", "http://app:2001").is_err()); // No password.
assert!(Config::from_values("hunter2", "/relative").is_err()); // No host.§Errors
Returns ConfigError::MissingPassword for an empty password, or
ConfigError::MissingUpstream / ConfigError::InvalidUpstream
if the upstream is not a valid absolute HTTP(S) URL. The bind
address uses the default 0.0.0.0:8000.
Sourcepub fn from_passwords(
passwords: &[&str],
upstream: &str,
) -> Result<Self, ConfigError>
pub fn from_passwords( passwords: &[&str], upstream: &str, ) -> Result<Self, ConfigError>
Build and validate from several explicit passwords (pure, env-free). Empty entries are ignored; at least one must remain, and all must be distinct. Any of them authenticates.
§Examples
assert!(Config::from_passwords(&["alice", "bob"], "http://app:2001").is_ok());
assert!(Config::from_passwords(&[], "http://app:2001").is_err()); // No password.
assert!(Config::from_passwords(&["x", "x"], "http://app:2001").is_err()); // Duplicate.§Errors
Returns ConfigError::MissingPassword if no password is non-empty,
ConfigError::DuplicatePassword if two passwords share a value, or
ConfigError::MissingUpstream / ConfigError::InvalidUpstream
if the upstream is not a valid absolute HTTP(S) URL. The bind
address uses the default 0.0.0.0:8000.
Sourcepub fn bind_address(&self) -> SocketAddr
pub fn bind_address(&self) -> SocketAddr
Validated IP socket address the service listens on.