Skip to main content

nanofish_client/
options.rs

1use embassy_time::Duration;
2use embassy_time_05 as embassy_time;
3
4/// Options for configuring the HTTP client
5pub struct HttpClientOptions {
6    /// Maximum number of retries for read operations
7    pub max_retries: usize,
8    /// Timeout duration for socket operations
9    pub socket_timeout: Duration,
10    /// Delay between retry attempts
11    pub retry_delay: Duration,
12    /// Delay after closing a socket before proceeding
13    pub socket_close_delay: Duration,
14}
15
16impl Default for HttpClientOptions {
17    fn default() -> Self {
18        Self {
19            max_retries: 5,
20            socket_timeout: Duration::from_secs(60),
21            retry_delay: Duration::from_millis(200),
22            socket_close_delay: Duration::from_millis(100),
23        }
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use embassy_time::Duration;
31
32    #[test]
33    fn test_default_options() {
34        let opts = HttpClientOptions::default();
35        assert_eq!(opts.max_retries, 5);
36        assert_eq!(opts.socket_timeout, Duration::from_secs(60));
37        assert_eq!(opts.retry_delay, Duration::from_millis(200));
38        assert_eq!(opts.socket_close_delay, Duration::from_millis(100));
39    }
40
41    #[test]
42    fn test_custom_options() {
43        let opts = HttpClientOptions {
44            max_retries: 2,
45            socket_timeout: Duration::from_secs(10),
46            retry_delay: Duration::from_millis(50),
47            socket_close_delay: Duration::from_millis(20),
48        };
49        assert_eq!(opts.max_retries, 2);
50        assert_eq!(opts.socket_timeout, Duration::from_secs(10));
51        assert_eq!(opts.retry_delay, Duration::from_millis(50));
52        assert_eq!(opts.socket_close_delay, Duration::from_millis(20));
53    }
54}