Skip to content

Commit

Permalink
v1.17: Allow to create HTTP Sender with custom Client (backport of #3…
Browse files Browse the repository at this point in the history
…3580) (#33660)

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>
(cherry picked from commit a226783)

Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
  • Loading branch information
mergify[bot] and fanatid authored Oct 11, 2023
1 parent d7dc802 commit 0e2bded
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions rpc-client/src/http_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,41 @@ impl HttpSender {
///
/// The URL is an HTTP URL, usually for port 8899.
pub fn new_with_timeout<U: ToString>(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 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,
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> {
Expand Down

0 comments on commit 0e2bded

Please sign in to comment.