1use std::net::SocketAddr;
4use std::time::Duration;
5
6#[derive(Debug, Clone)]
8pub struct ServerConfig {
9 pub addr: SocketAddr,
11 pub security_enabled: bool,
13 pub security_blocking: bool,
15 pub block_threshold: f32,
17 pub session_timeout: Duration,
19 pub max_body_size: usize,
21 pub logging: bool,
23 pub cors_enabled: bool,
25 pub model_path: Option<String>,
27}
28
29impl Default for ServerConfig {
30 fn default() -> Self {
31 Self {
32 addr: "127.0.0.1:3000".parse().unwrap(),
33 security_enabled: true,
34 security_blocking: false,
35 block_threshold: 0.8,
36 session_timeout: Duration::from_secs(300),
37 max_body_size: 10 * 1024 * 1024, logging: true,
39 cors_enabled: true,
40 model_path: None,
41 }
42 }
43}
44
45impl ServerConfig {
46 pub fn with_port(mut self, port: u16) -> Self {
48 self.addr = format!("127.0.0.1:{port}").parse().unwrap();
49 self
50 }
51
52 pub fn bind_all(mut self) -> Self {
54 let port = self.addr.port();
55 self.addr = format!("0.0.0.0:{port}").parse().unwrap();
56 self
57 }
58
59 pub fn with_addr(mut self, addr: SocketAddr) -> Self {
61 self.addr = addr;
62 self
63 }
64
65 pub fn with_security_blocking(mut self, threshold: f32) -> Self {
67 self.security_blocking = true;
68 self.block_threshold = threshold;
69 self
70 }
71
72 pub fn without_security(mut self) -> Self {
74 self.security_enabled = false;
75 self
76 }
77
78 pub fn with_model(mut self, path: &str) -> Self {
80 self.model_path = Some(path.to_string());
81 self
82 }
83
84 pub fn with_session_timeout(mut self, timeout: Duration) -> Self {
86 self.session_timeout = timeout;
87 self
88 }
89
90 pub fn with_max_body_size(mut self, size: usize) -> Self {
92 self.max_body_size = size;
93 self
94 }
95
96 pub fn without_logging(mut self) -> Self {
98 self.logging = false;
99 self
100 }
101
102 pub fn without_cors(mut self) -> Self {
104 self.cors_enabled = false;
105 self
106 }
107}