Skip to main content

braid_http/client/
config.rs

1//! Configuration for the Braid HTTP client.
2
3/// Configuration for the Braid HTTP client.
4#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct ClientConfig {
6    /// Maximum retries for failed requests.
7    pub max_retries: u32,
8    /// Base retry delay in milliseconds.
9    pub retry_delay_ms: u64,
10    /// Connection timeout in seconds.
11    pub connection_timeout_secs: u64,
12    /// Enable request logging.
13    pub enable_logging: bool,
14    /// Maximum concurrent subscriptions.
15    pub max_subscriptions: usize,
16    /// Threshold for auto-multiplexing.
17    pub auto_multiplex_threshold: usize,
18    /// Enable multiplexing for subscription requests.
19    pub enable_multiplex: bool,
20    /// Proxy URL (optional).
21    pub proxy_url: String,
22    /// Request timeout in milliseconds.
23    pub request_timeout_ms: u64,
24    /// Maximum total connections in the pool.
25    pub max_total_connections: u32,
26}
27
28impl Default for ClientConfig {
29    fn default() -> Self {
30        ClientConfig {
31            max_retries: 3,
32            retry_delay_ms: 1000,
33            connection_timeout_secs: 30,
34            enable_logging: false,
35            max_subscriptions: 100,
36            auto_multiplex_threshold: 3,
37            enable_multiplex: true,
38            proxy_url: String::new(),
39            request_timeout_ms: 30000,
40            max_total_connections: 100,
41        }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_default_config() {
51        let config = ClientConfig::default();
52        assert_eq!(config.max_retries, 3);
53        assert_eq!(config.retry_delay_ms, 1000);
54        assert_eq!(config.connection_timeout_secs, 30);
55        assert!(!config.enable_logging);
56        assert_eq!(config.max_subscriptions, 100);
57        assert_eq!(config.auto_multiplex_threshold, 3);
58        assert!(config.enable_multiplex);
59        assert_eq!(config.proxy_url, "");
60        assert_eq!(config.request_timeout_ms, 30000);
61        assert_eq!(config.max_total_connections, 100);
62    }
63
64    #[test]
65    fn test_custom_config() {
66        let config = ClientConfig {
67            max_retries: 5,
68            retry_delay_ms: 2000,
69            connection_timeout_secs: 60,
70            enable_logging: true,
71            max_subscriptions: 50,
72            auto_multiplex_threshold: 5,
73            enable_multiplex: false,
74            proxy_url: "http://proxy".to_string(),
75            request_timeout_ms: 1000,
76            max_total_connections: 40,
77        };
78        assert_eq!(config.max_retries, 5);
79        assert_eq!(config.retry_delay_ms, 2000);
80        assert_eq!(config.connection_timeout_secs, 60);
81        assert!(config.enable_logging);
82        assert_eq!(config.max_subscriptions, 50);
83        assert_eq!(config.auto_multiplex_threshold, 5);
84        assert!(!config.enable_multiplex);
85        assert_eq!(config.proxy_url, "http://proxy");
86        assert_eq!(config.request_timeout_ms, 1000);
87        assert_eq!(config.max_total_connections, 40);
88    }
89
90    #[test]
91    fn test_partial_override() {
92        let config = ClientConfig {
93            max_retries: 10,
94            ..Default::default()
95        };
96        assert_eq!(config.max_retries, 10);
97        assert_eq!(config.retry_delay_ms, 1000);
98    }
99
100    #[test]
101    fn test_clone() {
102        let config = ClientConfig::default();
103        let cloned = config.clone();
104        assert_eq!(config, cloned);
105    }
106
107    #[test]
108    fn test_debug() {
109        let config = ClientConfig::default();
110        let debug = format!("{:?}", config);
111        assert!(debug.contains("ClientConfig"));
112        assert!(debug.contains("max_retries"));
113    }
114}