flawless-http 1.0.0-beta.3

HTTP client for https://flawless.dev.
Documentation
use std::time::Duration;

/// Configuration settings for requests.
///
/// By default, the size limit is 100 Mb and the timeout duration is 120s.
#[derive(Debug, Clone, Copy)]
pub struct Config {
    /// Should be set to `true` if the performed call is idempotent.
    pub(crate) idempotent: bool,
    /// The duration the client should wait before timing out.
    pub(crate) timeout: Duration,
    /// A response body size limit in bytes.
    pub(crate) response_body_limit: u64,
}

impl Default for Config {
    fn default() -> Self {
        Self { idempotent: false, timeout: Duration::from_secs(120), response_body_limit: 10_000_000 }
    }
}

impl Config {
    /// The duration of time a request should wait on a response before returning a timeout error.
    ///
    /// Default: 120s
    pub fn timeout(&self) -> Duration {
        self.timeout
    }

    /// The body size limit of a response in bytes.
    ///
    /// Default: 10_000_000 (~10Mb)
    pub fn response_body_limit(&self) -> u64 {
        self.response_body_limit
    }

    pub(crate) fn set_timeout(&mut self, duration: Duration) {
        self.timeout = duration;
    }

    pub(crate) fn set_response_body_limit(&mut self, limit: u64) {
        self.response_body_limit = limit;
    }

    pub(crate) fn set_idempotent(&mut self, idempotent: bool) {
        self.idempotent = idempotent;
    }
}

impl From<Config> for flawless_wasabi::HttpConfig {
    fn from(value: Config) -> Self {
        flawless_wasabi::HttpConfig {
            idempotent: value.idempotent,
            timeout: value.timeout,
            response_body_limit: value.response_body_limit,
        }
    }
}