use hyper_custom_cert::HttpClient;
use std::collections::HashMap;
use std::time::Duration;
#[tokio::main]
async fn main() {
let mut headers = HashMap::new();
headers.insert("x-app".into(), "example".into());
let client = HttpClient::builder()
.with_timeout(Duration::from_secs(10))
.with_default_headers(headers)
.build();
let _response = client
.request_with_options("https://example.com", None)
.await
.expect("request should succeed on native targets");
#[cfg(feature = "rustls")]
{
let ca_pem: &[u8] =
b"-----BEGIN CERTIFICATE-----\n...your root ca...\n-----END CERTIFICATE-----\n";
let _rustls_client = HttpClient::builder()
.with_timeout(Duration::from_secs(10))
.with_root_ca_pem(ca_pem)
.build();
let _ = _rustls_client
.request_with_options("https://private.local", None)
.await;
}
#[cfg(feature = "insecure-dangerous")]
{
let _dev_client = HttpClient::with_self_signed_certs();
let _ = _dev_client
.request_with_options("https://localhost:8443", None)
.await;
let _dev_client2 = HttpClient::builder()
.insecure_accept_invalid_certs(true)
.build();
let _ = _dev_client2
.request_with_options("https://localhost:8443", None)
.await;
}
println!("Example finished. See README for feature flags and commands.");
}