Allow to create HTTP Sender with custom Client (#33580)
* Allow to create HTTP Sender with custom Client * Update rpc-client/src/http_sender.rs Co-authored-by: Tyera <teulberg@gmail.com> --------- Co-authored-by: Tyera <teulberg@gmail.com>
This commit is contained in:
parent
982d29cf60
commit
a22678312e
|
@ -47,6 +47,31 @@ impl HttpSender {
|
||||||
///
|
///
|
||||||
/// The URL is an HTTP URL, usually for port 8899.
|
/// The URL is an HTTP URL, usually for port 8899.
|
||||||
pub fn new_with_timeout<U: ToString>(url: U, timeout: Duration) -> Self {
|
pub fn new_with_timeout<U: ToString>(url: U, timeout: Duration) -> Self {
|
||||||
|
Self::new_with_client(
|
||||||
|
url,
|
||||||
|
reqwest::Client::builder()
|
||||||
|
.default_headers(Self::default_headers())
|
||||||
|
.timeout(timeout)
|
||||||
|
.pool_idle_timeout(timeout)
|
||||||
|
.build()
|
||||||
|
.expect("build rpc client"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create an HTTP RPC sender.
|
||||||
|
///
|
||||||
|
/// Most flexible way to create a sender. Pass a created `reqwest::Client`.
|
||||||
|
pub fn new_with_client<U: ToString>(url: U, client: reqwest::Client) -> Self {
|
||||||
|
Self {
|
||||||
|
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();
|
let mut default_headers = header::HeaderMap::new();
|
||||||
default_headers.append(
|
default_headers.append(
|
||||||
header::HeaderName::from_static("solana-client"),
|
header::HeaderName::from_static("solana-client"),
|
||||||
|
@ -55,22 +80,7 @@ impl HttpSender {
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
default_headers
|
||||||
let client = Arc::new(
|
|
||||||
reqwest::Client::builder()
|
|
||||||
.default_headers(default_headers)
|
|
||||||
.timeout(timeout)
|
|
||||||
.pool_idle_timeout(timeout)
|
|
||||||
.build()
|
|
||||||
.expect("build rpc client"),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
client,
|
|
||||||
url: url.to_string(),
|
|
||||||
request_id: AtomicU64::new(0),
|
|
||||||
stats: RwLock::new(RpcTransportStats::default()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue