use std::time::Duration;
pub(crate) fn platform_tls_config() -> ureq::tls::TlsConfig {
ureq::tls::TlsConfig::builder()
.root_certs(ureq::tls::RootCerts::PlatformVerifier)
.build()
}
pub(crate) fn ureq_agent(config: ureq::config::Config) -> ureq::Agent {
ureq::Agent::new_with_config(config)
}
pub(crate) fn ureq_agent_with_timeouts(
timeout_resolve: Option<Duration>,
timeout_connect: Option<Duration>,
timeout_recv_response: Option<Duration>,
) -> ureq::Agent {
agent_with_redirect_policy(
timeout_resolve,
timeout_connect,
timeout_recv_response,
false,
)
}
pub(crate) fn ureq_agent_without_redirects(
timeout_resolve: Option<Duration>,
timeout_connect: Option<Duration>,
timeout_recv_response: Option<Duration>,
) -> ureq::Agent {
agent_with_redirect_policy(
timeout_resolve,
timeout_connect,
timeout_recv_response,
true,
)
}
fn agent_with_redirect_policy(
timeout_resolve: Option<Duration>,
timeout_connect: Option<Duration>,
timeout_recv_response: Option<Duration>,
deny_redirects: bool,
) -> ureq::Agent {
let mut config = ureq::config::Config::builder()
.tls_config(platform_tls_config())
.timeout_resolve(timeout_resolve)
.timeout_connect(timeout_connect)
.timeout_recv_response(timeout_recv_response);
if deny_redirects {
config = config.max_redirects(0);
}
config.build().into()
}