Skip to content

Commit

Permalink
Merge branch 'main' into rustls-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
h4sh3d authored May 30, 2024
2 parents a9f0919 + 4e6e923 commit 74280ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 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
2 changes: 1 addition & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// TODO: remove this when clippy error goes away...
#![allow(clippy::incorrect_clone_impl_on_copy_type)]
#![allow(clippy::non_canonical_clone_impl)]

use crate::util::*;
use chrono::prelude::*;
Expand Down

0 comments on commit 74280ed

Please sign in to comment.