Skip to content

Commit 0a449f6

Browse files
committed
feat: Add HTTP client User-Agent header
Identify the download client as a proxy server to the crates.io servers.
1 parent 70867b4 commit 0a449f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const JSON_HTTP_CTYPE: &str = "Content-Type: application/json; charset=utf-8";
9696
/// Program version tag: `"<major>.<minor>.<patch>"`
9797
const VERSION: &str = env!("CARGO_PKG_VERSION");
9898

99+
/// HTTP client User Agent string
100+
const HTTP_USER_AGENT: &str = concat!("crates-io-proxy/", env!("CARGO_PKG_VERSION"));
101+
99102
/// Proxy server configuration
100103
#[derive(Debug, Clone)]
101104
struct ProxyConfig {
@@ -135,7 +138,10 @@ struct IndexResponse {
135138
/// The global agent instance is required to use HTTP request pipelining.
136139
fn ureq_agent() -> ureq::Agent {
137140
static AGENT: OnceLock<ureq::Agent> = OnceLock::new();
138-
AGENT.get_or_init(ureq::agent).clone()
141+
142+
AGENT
143+
.get_or_init(|| ureq::builder().user_agent(HTTP_USER_AGENT).build())
144+
.clone()
139145
}
140146

141147
/// Downloads the crate file from the upstream download server

0 commit comments

Comments
 (0)