lean_ctx/core/
http_client.rs1use std::time::Duration;
2
3pub fn platform_tls_config() -> ureq::tls::TlsConfig {
10 ureq::tls::TlsConfig::builder()
11 .root_certs(ureq::tls::RootCerts::PlatformVerifier)
12 .build()
13}
14
15pub fn ureq_agent(config: ureq::config::Config) -> ureq::Agent {
18 ureq::Agent::new_with_config(config)
19}
20
21pub fn ureq_agent_with_timeouts(
24 timeout_resolve: Option<Duration>,
25 timeout_connect: Option<Duration>,
26 timeout_recv_response: Option<Duration>,
27) -> ureq::Agent {
28 agent_with_redirect_policy(
29 timeout_resolve,
30 timeout_connect,
31 timeout_recv_response,
32 false,
33 )
34}
35
36pub(crate) fn ureq_agent_without_redirects(
38 timeout_resolve: Option<Duration>,
39 timeout_connect: Option<Duration>,
40 timeout_recv_response: Option<Duration>,
41) -> ureq::Agent {
42 agent_with_redirect_policy(
43 timeout_resolve,
44 timeout_connect,
45 timeout_recv_response,
46 true,
47 )
48}
49
50fn agent_with_redirect_policy(
51 timeout_resolve: Option<Duration>,
52 timeout_connect: Option<Duration>,
53 timeout_recv_response: Option<Duration>,
54 deny_redirects: bool,
55) -> ureq::Agent {
56 let mut config = ureq::config::Config::builder()
57 .tls_config(platform_tls_config())
58 .timeout_resolve(timeout_resolve)
59 .timeout_connect(timeout_connect)
60 .timeout_recv_response(timeout_recv_response);
61 if deny_redirects {
62 config = config.max_redirects(0);
63 }
64 config.build().into()
65}