use reqwest::redirect::Policy;
use std::sync::OnceLock;
use std::time::Duration;
use crate::fetcher::dns::shared_resolver;
pub fn install_ring_provider() {
static INSTALLED: OnceLock<()> = OnceLock::new();
INSTALLED.get_or_init(|| {
rustls::crypto::ring::default_provider()
.install_default()
.ok();
});
}
pub fn build_http_client(user_agent: &str, timeout: Duration) -> reqwest::Client {
install_ring_provider();
reqwest::Client::builder()
.user_agent(user_agent)
.timeout(timeout)
.redirect(Policy::limited(10))
.dns_resolver(shared_resolver())
.build()
.expect("reqwest::Client::builder() should not fail with these defaults")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn builds_with_defaults() {
let _client = build_http_client("test/0.1", Duration::from_secs(15));
}
}