From 972edc92f6ab06e883d0e79184b69c8a92c3cee8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 28 Jun 2022 01:10:43 +0000 Subject: [PATCH] Add user-agent header to Solana rust client requests (#26274) (cherry picked from commit 558dd530256d9f93c73e55814801820d042ee75d) Co-authored-by: steveluscher --- client/src/http_sender.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/src/http_sender.rs b/client/src/http_sender.rs index 66d68e1382e1c9..71c788824cef97 100644 --- a/client/src/http_sender.rs +++ b/client/src/http_sender.rs @@ -12,7 +12,7 @@ use { log::*, reqwest::{ self, - header::{CONTENT_TYPE, RETRY_AFTER}, + header::{self, CONTENT_TYPE, RETRY_AFTER}, StatusCode, }, std::{ @@ -46,8 +46,17 @@ 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(); + let user_agent_string = + format!("rust-solana-client/{}", solana_version::Version::default()); + default_headers.append( + header::USER_AGENT, + header::HeaderValue::from_str(user_agent_string.as_str()).unwrap(), + ); + let client = Arc::new( reqwest::Client::builder() + .default_headers(default_headers) .timeout(timeout) .build() .expect("build rpc client"),