Skip to content

Commit

Permalink
set a user agent in our api client
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Apr 20, 2024
1 parent 72964bf commit e9c45e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
32 changes: 19 additions & 13 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,20 +709,26 @@ impl Client {
file: client_cert_path.clone(),
}
})?;
let pem = reqwest::Identity::from_pem(&buf).map_err(|e| {
Error::LoadClientCertReqwest {
source: e,
file: client_cert_path.clone(),
}
})?;
Ok(reqwest::Client::builder().identity(pem).build().map_err(
|e| Error::LoadClientCertReqwest {
source: e,
file: client_cert_path.clone(),
},
)?)
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")
))
.identity(pem)
.build()
.map_err(|e| Error::CreateReqwestClient { source: e })?)
} else {
Ok(reqwest::Client::new())
Ok(reqwest::Client::builder()
.user_agent(format!(
"{}-{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
))
.build()
.map_err(|e| Error::CreateReqwestClient { source: e })?)
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub enum Error {
file: std::path::PathBuf,
},

#[error("failed to create reqwest client")]
CreateReqwestClient { source: reqwest::Error },

#[error("failed to decrypt")]
Decrypt { source: block_padding::UnpadError },

Expand Down Expand Up @@ -127,12 +130,6 @@ pub enum Error {
file: std::path::PathBuf,
},

#[error("failed to load client cert from {}", .file.display())]
LoadClientCertReqwest {
source: reqwest::Error,
file: std::path::PathBuf,
},

#[error("invalid padding")]
Padding,

Expand Down

0 comments on commit e9c45e6

Please sign in to comment.