Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a way to provide a custom User-Agent #1429

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `[tendermint-rpc]` Add a way to specify custom User-Agent for HttpClient
([#1425](https://github.com/informalsystems/tendermint-rs/issues/1425))
10 changes: 9 additions & 1 deletion rpc/src/client/transport/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Builder {
url: HttpClientUrl,
compat: CompatMode,
proxy_url: Option<HttpClientUrl>,
user_agent: Option<String>,
timeout: Duration,
}

Expand Down Expand Up @@ -93,10 +94,16 @@ impl Builder {
self
}

/// Specify the custom User-Agent header the client.
pub fn user_agent(mut self, agent: String) -> Self {
self.user_agent = Some(agent);
self
}

/// Try to create a client with the options specified for this builder.
pub fn build(self) -> Result<HttpClient, Error> {
let builder = reqwest::ClientBuilder::new()
.user_agent(USER_AGENT)
.user_agent(self.user_agent.unwrap_or(USER_AGENT.to_string()))
.timeout(self.timeout);
let inner = match self.proxy_url {
None => builder.build().map_err(Error::http)?,
Expand Down Expand Up @@ -152,6 +159,7 @@ impl HttpClient {
url,
compat: Default::default(),
proxy_url: None,
user_agent: None,
timeout: Duration::from_secs(30),
}
}
Expand Down
Loading