Skip to content

Commit

Permalink
refactor(api): extract user_agent variable
Browse files Browse the repository at this point in the history
  • Loading branch information
davla committed Dec 1, 2024
1 parent 5d970fc commit e07f0d7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,11 @@ impl Client {
axum::http::HeaderValue::from_str(&DEVICE_TYPE.to_string())
.unwrap(),
);
let user_agent = format!(
"{}/{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
);
if let Some(client_cert_path) = self.client_cert_path.as_ref() {
let mut buf = Vec::new();
let mut f = tokio::fs::File::open(client_cert_path)
Expand All @@ -833,22 +838,14 @@ impl Client {
let pem = reqwest::Identity::from_pem(&buf)
.map_err(|e| Error::CreateReqwestClient { source: e })?;
Ok(reqwest::Client::builder()
.user_agent(format!(
"{}/{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
))
.user_agent(user_agent)
.identity(pem)
.default_headers(default_headers)
.build()
.map_err(|e| Error::CreateReqwestClient { source: e })?)
} else {
Ok(reqwest::Client::builder()
.user_agent(format!(
"{}/{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
))
.user_agent(user_agent)
.default_headers(default_headers)
.build()
.map_err(|e| Error::CreateReqwestClient { source: e })?)
Expand Down

0 comments on commit e07f0d7

Please sign in to comment.