Skip to content
Merged
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
19 changes: 18 additions & 1 deletion crates/lib/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use reqwest::{Client, ClientBuilder};

#[cfg(not(any(target_os = "macos", target_os = "windows")))]
Expand All @@ -12,10 +14,25 @@ pub fn build_client() -> Result<Client, Box<dyn std::error::Error>> {
builder = builder.add_root_certificate(cert);
}

builder = builder.user_agent(get_user_agent());

Ok(builder.build()?)
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
pub fn build_client() -> Result<Client, Box<dyn std::error::Error>> {
Ok(ClientBuilder::new().build()?)
Ok(ClientBuilder::new().user_agent(get_user_agent()).build()?)
}

fn get_user_agent() -> String {
let version = env!("CARGO_PKG_VERSION");
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
let group = env::var("PKGX_USER_AGENT_GROUP");
let name = if group.is_ok() {
format!("pkgx[{}]", group.unwrap())
} else {
"pkgx".to_string()
};
format!("{name}/{version} ({os}; {arch})")
}