camel_component_http/
config.rs1#[derive(Debug, Clone, PartialEq)]
2pub struct HttpConfig {
3 pub connect_timeout_ms: u64,
4 pub pool_max_idle_per_host: usize,
5 pub pool_idle_timeout_ms: u64,
6 pub follow_redirects: bool,
7 pub response_timeout_ms: u64,
8 pub max_body_size: usize,
9 pub max_request_body: usize,
10 pub allow_private_ips: bool,
11 pub blocked_hosts: Vec<String>,
12}
13
14impl Default for HttpConfig {
15 fn default() -> Self {
16 Self {
17 connect_timeout_ms: 5_000,
18 pool_max_idle_per_host: 100,
19 pool_idle_timeout_ms: 90_000,
20 follow_redirects: false,
21 response_timeout_ms: 30_000,
22 max_body_size: 10_485_760,
23 max_request_body: 2_097_152,
24 allow_private_ips: false,
25 blocked_hosts: Vec::new(),
26 }
27 }
28}
29
30impl HttpConfig {
31 pub fn with_connect_timeout_ms(mut self, ms: u64) -> Self {
32 self.connect_timeout_ms = ms;
33 self
34 }
35 pub fn with_pool_max_idle_per_host(mut self, n: usize) -> Self {
36 self.pool_max_idle_per_host = n;
37 self
38 }
39 pub fn with_pool_idle_timeout_ms(mut self, ms: u64) -> Self {
40 self.pool_idle_timeout_ms = ms;
41 self
42 }
43 pub fn with_follow_redirects(mut self, follow: bool) -> Self {
44 self.follow_redirects = follow;
45 self
46 }
47 pub fn with_response_timeout_ms(mut self, ms: u64) -> Self {
48 self.response_timeout_ms = ms;
49 self
50 }
51 pub fn with_max_body_size(mut self, n: usize) -> Self {
52 self.max_body_size = n;
53 self
54 }
55 pub fn with_max_request_body(mut self, n: usize) -> Self {
56 self.max_request_body = n;
57 self
58 }
59 pub fn with_allow_private_ips(mut self, allow: bool) -> Self {
60 self.allow_private_ips = allow;
61 self
62 }
63 pub fn with_blocked_hosts(mut self, hosts: Vec<String>) -> Self {
64 self.blocked_hosts = hosts;
65 self
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_http_config_defaults() {
75 let cfg = HttpConfig::default();
76 assert_eq!(cfg.connect_timeout_ms, 5_000);
77 assert_eq!(cfg.pool_max_idle_per_host, 100);
78 assert_eq!(cfg.pool_idle_timeout_ms, 90_000);
79 assert!(!cfg.follow_redirects);
80 assert_eq!(cfg.response_timeout_ms, 30_000);
81 assert_eq!(cfg.max_body_size, 10_485_760);
82 assert_eq!(cfg.max_request_body, 2_097_152);
83 assert!(!cfg.allow_private_ips);
84 assert!(cfg.blocked_hosts.is_empty());
85 }
86
87 #[test]
88 fn test_http_config_builder() {
89 let cfg = HttpConfig::default()
90 .with_connect_timeout_ms(1_000)
91 .with_pool_max_idle_per_host(50)
92 .with_follow_redirects(true)
93 .with_allow_private_ips(true)
94 .with_blocked_hosts(vec!["evil.com".to_string()]);
95 assert_eq!(cfg.connect_timeout_ms, 1_000);
96 assert_eq!(cfg.pool_max_idle_per_host, 50);
97 assert!(cfg.follow_redirects);
98 assert!(cfg.allow_private_ips);
99 assert_eq!(cfg.blocked_hosts, vec!["evil.com".to_string()]);
100 assert_eq!(cfg.response_timeout_ms, 30_000);
101 }
102}