Skip to main content

nyquest_interface/client/
options.rs

1//! Configuration options for HTTP clients.
2
3use std::{borrow::Cow, time::Duration};
4
5/// Defines how the HTTP client should handle response caching.
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
7pub enum CachingBehavior {
8    /// Caching is completely disabled.
9    Disabled,
10    /// Best effort caching behavior based on the backend capabilities.
11    #[default]
12    BestEffort,
13}
14
15/// Configuration options for proxy settings.
16#[derive(Debug, Clone, Default, PartialEq, Eq)]
17pub enum ProxyOptions {
18    /// Use the system's default proxy settings.
19    #[default]
20    Default,
21    /// Disable system's default proxy settings and do not use any proxy.
22    None,
23    /// Use custom proxy settings.
24    Custom {
25        /// The proxy URL to use for HTTP requests.
26        http: Option<Cow<'static, str>>,
27        /// The proxy URL to use for HTTPS requests.
28        https: Option<Cow<'static, str>>,
29        /// Optional list of host patterns that should bypass the proxy.
30        proxy_bypass: Option<Cow<'static, str>>,
31    },
32}
33
34/// Configuration options for creating a nyquest HTTP client.
35#[derive(Debug, Clone)]
36pub struct ClientOptions {
37    /// Optional base URL prepended to all request URLs.
38    pub base_url: Option<String>,
39    /// Optional User-Agent header value to use for all requests.
40    pub user_agent: Option<String>,
41    /// Headers to include in all requests by default.
42    pub default_headers: Vec<(String, String)>,
43    /// Controls the caching behavior for HTTP responses.
44    pub caching_behavior: CachingBehavior,
45    /// Configuration options for proxy settings.
46    pub proxy_options: ProxyOptions,
47    /// Whether to enable cookie handling.
48    pub use_cookies: bool,
49    /// Whether to automatically follow redirect responses.
50    pub follow_redirects: bool,
51    /// Optional maximum buffer size for response bodies.
52    pub max_response_buffer_size: Option<u64>,
53    /// Optional timeout duration for requests.
54    pub request_timeout: Option<Duration>,
55    /// Whether to ignore SSL certificate errors.
56    pub ignore_certificate_errors: bool,
57    // TODO: auth
58    // TODO: redirects
59}
60
61impl Default for ClientOptions {
62    #[inline]
63    fn default() -> Self {
64        Self {
65            base_url: None,
66            user_agent: None,
67            default_headers: vec![],
68            caching_behavior: CachingBehavior::default(),
69            proxy_options: ProxyOptions::default(),
70            use_cookies: true,
71            follow_redirects: true,
72            max_response_buffer_size: None,
73            request_timeout: None,
74            ignore_certificate_errors: false,
75        }
76    }
77}