pub struct ServerConfig {
pub allowed_origins: Vec<String>,
pub api_key: Option<String>,
pub require_auth_for_metrics: bool,
}Expand description
HTTP server configuration.
Controls CORS, authentication, and other HTTP-related security settings.
§Security
CWE-942 (Overly Permissive CORS), CWE-306 (Missing Authentication):
Production deployments should configure explicit allowed_origins and
enable API key authentication.
Fields§
§allowed_origins: Vec<String>Allowed CORS origins.
- Empty vector: No CORS headers (most restrictive)
["*"]: Allow all origins (NOT RECOMMENDED for production)- Explicit list: Only allow specified origins (RECOMMENDED)
§Security
CWE-942: Using ["*"] allows any website to make requests to
your server, potentially exposing sensitive data.
api_key: Option<String>Optional API key for request authentication.
When set, all API requests must include the header:
X-API-Key: <key>
§Security
CWE-306: Without authentication, any client can execute queries. Enable this for any deployment accessible beyond localhost.
require_auth_for_metrics: boolWhether to require API key for metrics endpoint.
Default: false (metrics are public for observability tooling)
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn development() -> Self
pub fn development() -> Self
Create a permissive config for local development only.
§Security
WARNING: Do not use in production. This config allows all CORS origins and has no authentication.
Sourcepub fn production(allowed_origins: Vec<String>, api_key: String) -> Self
pub fn production(allowed_origins: Vec<String>, api_key: String) -> Self
Create a production config with explicit origins and required API key.
§Panics
Panics if api_key is empty.
Sourcepub fn security_warning(&self) -> Option<&'static str>
pub fn security_warning(&self) -> Option<&'static str>
Returns a security warning if the config is insecure.
Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§fn clone(&self) -> ServerConfig
fn clone(&self) -> ServerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServerConfig
impl Debug for ServerConfig
Auto Trait Implementations§
impl Freeze for ServerConfig
impl RefUnwindSafe for ServerConfig
impl Send for ServerConfig
impl Sync for ServerConfig
impl Unpin for ServerConfig
impl UnsafeUnpin for ServerConfig
impl UnwindSafe for ServerConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more