use std::net::SocketAddr;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct HealthConfig {
pub enabled: bool,
pub liveness: String,
pub readiness: String,
pub bind: Option<SocketAddr>,
pub max_connections: usize,
}
impl Default for HealthConfig {
fn default() -> Self {
Self {
enabled: true,
liveness: "/healthz".into(),
readiness: "/readyz".into(),
bind: None,
max_connections: 64,
}
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct LogConfig {
pub format: LogFormat,
pub level: Option<String>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
#[default]
Text,
Json,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct LimitsConfig {
pub max_body_bytes: u64,
pub max_header_bytes: usize,
pub max_uri_bytes: usize,
pub max_connections: usize,
pub pool_wait_ms: u64,
pub header_read_ms: u64,
pub body_read_ms: u64,
pub max_form_parts: usize,
pub max_field_bytes: u64,
pub max_file_bytes: u64,
}
impl Default for LimitsConfig {
fn default() -> Self {
Self {
max_body_bytes: 1024 * 1024, max_header_bytes: 16 * 1024, max_uri_bytes: 8 * 1024, max_connections: 1024,
pool_wait_ms: 5_000,
header_read_ms: 30_000,
body_read_ms: 30_000,
max_form_parts: 64,
max_field_bytes: 64 * 1024, max_file_bytes: 10 * 1024 * 1024, }
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct ShutdownConfig {
pub grace: u64,
pub stream_grace: u64,
pub readiness_delay: Option<u64>,
}
impl Default for ShutdownConfig {
fn default() -> Self {
Self {
grace: 30,
stream_grace: 5,
readiness_delay: None,
}
}
}
impl ShutdownConfig {
pub fn grace(&self) -> std::time::Duration {
std::time::Duration::from_secs(self.grace)
}
pub fn total_grace(&self) -> std::time::Duration {
std::time::Duration::from_secs(self.grace + self.stream_grace)
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct CorsConfig {
pub origins: Option<Vec<String>>,
pub methods: Option<Vec<String>>,
pub headers: Option<Vec<String>>,
pub expose_headers: Option<Vec<String>>,
pub credentials: bool,
pub max_age: Option<u64>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct RateLimitConfig {
pub enabled: bool,
pub requests: u32,
pub window: u64,
pub trust_forwarded_for: bool,
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
enabled: false,
requests: 100,
window: 60,
trust_forwarded_for: false,
}
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct TlsConfig {
pub enabled: bool,
pub cert: Option<PathBuf>,
pub key: Option<PathBuf>,
pub min_version: Option<String>,
pub handshake_ms: Option<u64>,
}
pub(crate) const TLS_MIN_VERSIONS: [&str; 2] = ["1.2", "1.3"];