From 1317ebc3ed8d9829b43d1d79e9a40d416e8059d2 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sat, 7 Oct 2023 12:01:43 +0400 Subject: [PATCH 1/2] Allow to create HTTP Sender with custom Client --- rpc-client/src/http_sender.rs | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/rpc-client/src/http_sender.rs b/rpc-client/src/http_sender.rs index 902f86ce631a48..4d1fad4dca8709 100644 --- a/rpc-client/src/http_sender.rs +++ b/rpc-client/src/http_sender.rs @@ -47,31 +47,41 @@ impl HttpSender { /// /// The URL is an HTTP URL, usually for port 8899. pub fn new_with_timeout(url: U, timeout: Duration) -> Self { - let mut default_headers = header::HeaderMap::new(); - default_headers.append( - header::HeaderName::from_static("solana-client"), - header::HeaderValue::from_str( - format!("rust/{}", solana_version::Version::default()).as_str(), - ) - .unwrap(), - ); - - let client = Arc::new( + Self::new_with_client( + url, reqwest::Client::builder() - .default_headers(default_headers) + .default_headers(Self::default_headers()) .timeout(timeout) .pool_idle_timeout(timeout) .build() .expect("build rpc client"), - ); + ) + } + /// Create an HTTP RPC sender. + /// + /// Most flexiable way to create sender. Accept created `reqwest::Client`. + pub fn new_with_client(url: U, client: reqwest::Client) -> Self { Self { - client, + client: Arc::new(client), url: url.to_string(), request_id: AtomicU64::new(0), stats: RwLock::new(RpcTransportStats::default()), } } + + /// Create default headers used by HTTP Sender. + pub fn default_headers() -> header::HeaderMap { + let mut default_headers = header::HeaderMap::new(); + default_headers.append( + header::HeaderName::from_static("solana-client"), + header::HeaderValue::from_str( + format!("rust/{}", solana_version::Version::default()).as_str(), + ) + .unwrap(), + ); + default_headers + } } struct StatsUpdater<'a> { From 90273e7be36354e9bacf1f893f518239559ea69e Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Tue, 10 Oct 2023 20:58:41 +0400 Subject: [PATCH 2/2] Update rpc-client/src/http_sender.rs Co-authored-by: Tyera --- rpc-client/src/http_sender.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc-client/src/http_sender.rs b/rpc-client/src/http_sender.rs index 4d1fad4dca8709..6ef22cc42c842a 100644 --- a/rpc-client/src/http_sender.rs +++ b/rpc-client/src/http_sender.rs @@ -60,7 +60,7 @@ impl HttpSender { /// Create an HTTP RPC sender. /// - /// Most flexiable way to create sender. Accept created `reqwest::Client`. + /// Most flexible way to create a sender. Pass a created `reqwest::Client`. pub fn new_with_client(url: U, client: reqwest::Client) -> Self { Self { client: Arc::new(client),