Skip to content

Commit

Permalink
Merge branch 'main' into clippy-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
h4sh3d authored May 30, 2024
2 parents cde12a2 + 131b554 commit 15a2e4d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ use std::{
num::NonZeroU64,
ops::{Deref, RangeInclusive},
sync::Arc,
time::Duration,
};
use tracing::*;
use uuid::Uuid;
Expand Down Expand Up @@ -248,6 +249,7 @@ struct RpcClientConfig {
#[cfg_attr(docsrs, doc(cfg(feature = "rpc_authentication")))]
rpc_auth: RpcAuthentication,
proxy_address: Option<String>,
timeout: Option<Duration>,
}

/// Builder for generating a configured [`RpcClient`].
Expand All @@ -270,6 +272,7 @@ impl RpcClientBuilder {
#[cfg(feature = "rpc_authentication")]
rpc_auth: RpcAuthentication::None,
proxy_address: None,
timeout: None,
},
}
}
Expand All @@ -288,17 +291,23 @@ impl RpcClientBuilder {
self
}

/// Configures default request timeout.
pub fn timeout(mut self, timeout: Duration) -> Self {
self.config.timeout = Some(timeout);
self
}

/// Build and return the fully configured RPC client.
pub fn build(self, addr: impl Into<String>) -> anyhow::Result<RpcClient> {
let config = self.config;
let http_client_builder = reqwest::ClientBuilder::new();
let http_client = if let Some(proxy_address) = config.proxy_address {
http_client_builder
.proxy(reqwest::Proxy::all(proxy_address)?)
.build()?
} else {
http_client_builder.build()?
let mut http_client_builder = reqwest::ClientBuilder::new();
if let Some(proxy_address) = config.proxy_address {
http_client_builder = http_client_builder.proxy(reqwest::Proxy::all(proxy_address)?);
};
if let Some(timeout) = config.timeout {
http_client_builder = http_client_builder.timeout(timeout);
};
let http_client = http_client_builder.build()?;
Ok(RpcClient {
inner: CallerWrapper(Arc::new(RemoteCaller {
http_client,
Expand Down

0 comments on commit 15a2e4d

Please sign in to comment.