Skip to content

feat: Add HTTP client User-Agent header #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2024
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
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
Loading