Skip to main content

cargo_dist/
net.rs

1//! Centralized logic for initializing http clients to
2//! ensure uniform configuration.
3
4use crate::errors::DistResult;
5use axoasset::reqwest;
6
7/// Settings for http clients
8///
9/// Any settings that should apply to all http requests should
10/// be stored here, to avoid different configurations.
11#[derive(Debug, Clone, Default)]
12pub struct ClientSettings {}
13
14impl ClientSettings {
15    /// Create new ClientSettings using all necessary values
16    pub fn new() -> Self {
17        Self::default()
18    }
19}
20
21/// Create a raw reqwest client
22///
23/// As of this writing this shouldn't be used/exposed, as we'd prefer
24/// to avoid proliferating random http clients. For now AxoClient
25/// is sufficient.
26fn create_reqwest_client(ClientSettings {}: &ClientSettings) -> DistResult<reqwest::Client> {
27    let client = reqwest::Client::builder()
28        .build()
29        .expect("failed to initialize http client");
30    Ok(client)
31}
32
33/// Create an AxoClient
34///
35/// Ideally this should be called only once and reused!
36pub fn create_axoasset_client(settings: &ClientSettings) -> DistResult<axoasset::AxoClient> {
37    let client = create_reqwest_client(settings)?;
38    Ok(axoasset::AxoClient::with_reqwest(client))
39}