Skip to content

Commit e07f0d7

Browse files
committed
refactor(api): extract user_agent variable
1 parent 5d970fc commit e07f0d7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/api.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ impl Client {
816816
axum::http::HeaderValue::from_str(&DEVICE_TYPE.to_string())
817817
.unwrap(),
818818
);
819+
let user_agent = format!(
820+
"{}/{}",
821+
env!("CARGO_PKG_NAME"),
822+
env!("CARGO_PKG_VERSION")
823+
);
819824
if let Some(client_cert_path) = self.client_cert_path.as_ref() {
820825
let mut buf = Vec::new();
821826
let mut f = tokio::fs::File::open(client_cert_path)
@@ -833,22 +838,14 @@ impl Client {
833838
let pem = reqwest::Identity::from_pem(&buf)
834839
.map_err(|e| Error::CreateReqwestClient { source: e })?;
835840
Ok(reqwest::Client::builder()
836-
.user_agent(format!(
837-
"{}/{}",
838-
env!("CARGO_PKG_NAME"),
839-
env!("CARGO_PKG_VERSION")
840-
))
841+
.user_agent(user_agent)
841842
.identity(pem)
842843
.default_headers(default_headers)
843844
.build()
844845
.map_err(|e| Error::CreateReqwestClient { source: e })?)
845846
} else {
846847
Ok(reqwest::Client::builder()
847-
.user_agent(format!(
848-
"{}/{}",
849-
env!("CARGO_PKG_NAME"),
850-
env!("CARGO_PKG_VERSION")
851-
))
848+
.user_agent(user_agent)
852849
.default_headers(default_headers)
853850
.build()
854851
.map_err(|e| Error::CreateReqwestClient { source: e })?)

0 commit comments

Comments
 (0)