Skip to content

Commit

Permalink
feat: Add HTTP client User-Agent header
Browse files Browse the repository at this point in the history
Identify the download client as a proxy server to the crates.io servers.
  • Loading branch information
ravenexp committed Apr 30, 2024
1 parent 70867b4 commit 0a449f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ const JSON_HTTP_CTYPE: &str = "Content-Type: application/json; charset=utf-8";
/// Program version tag: `"<major>.<minor>.<patch>"`
const VERSION: &str = env!("CARGO_PKG_VERSION");

/// HTTP client User Agent string
const HTTP_USER_AGENT: &str = concat!("crates-io-proxy/", env!("CARGO_PKG_VERSION"));

/// Proxy server configuration
#[derive(Debug, Clone)]
struct ProxyConfig {
Expand Down Expand Up @@ -135,7 +138,10 @@ struct IndexResponse {
/// The global agent instance is required to use HTTP request pipelining.
fn ureq_agent() -> ureq::Agent {
static AGENT: OnceLock<ureq::Agent> = OnceLock::new();
AGENT.get_or_init(ureq::agent).clone()

AGENT
.get_or_init(|| ureq::builder().user_agent(HTTP_USER_AGENT).build())
.clone()
}

/// Downloads the crate file from the upstream download server
Expand Down

0 comments on commit 0a449f6

Please sign in to comment.