Skip to content

Commit 67a3ab2

Browse files
committed
feat(download): reflect the download/TLS backends in the user agent
1 parent 2345c2c commit 67a3ab2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

download/src/lib.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ pub use crate::errors::*;
1212

1313
/// User agent header value for HTTP request.
1414
/// See: https://github.com/rust-lang/rustup/issues/2860.
15-
const USER_AGENT: &str = concat!("rustup/", env!("CARGO_PKG_VERSION"));
15+
const CURL_USER_AGENT: &str = concat!("rustup/", env!("CARGO_PKG_VERSION"), " (curl)");
16+
const REQWEST_DEFAULT_TLS_USER_AGENT: &str = concat!(
17+
"rustup/",
18+
env!("CARGO_PKG_VERSION"),
19+
" (reqwest; default-tls)"
20+
);
21+
const REQWEST_RUSTLS_TLS_USER_AGENT: &str =
22+
concat!("rustup/", env!("CARGO_PKG_VERSION"), " (reqwest; rustls)");
1623

1724
#[derive(Debug, Copy, Clone)]
1825
pub enum Backend {
@@ -175,7 +182,7 @@ pub mod curl {
175182

176183
handle.url(url.as_ref())?;
177184
handle.follow_location(true)?;
178-
handle.useragent(super::USER_AGENT)?;
185+
handle.useragent(super::CURL_USER_AGENT)?;
179186

180187
if resume_from > 0 {
181188
handle.resume_from(resume_from)?;
@@ -322,14 +329,18 @@ pub mod reqwest_be {
322329
fn client_generic() -> ClientBuilder {
323330
Client::builder()
324331
.gzip(false)
325-
.user_agent(super::USER_AGENT)
326332
.proxy(Proxy::custom(env_proxy))
327333
.timeout(Duration::from_secs(30))
328334
}
329335

330336
#[cfg(feature = "reqwest-rustls-tls")]
331337
static CLIENT_RUSTLS_TLS: Lazy<Client> = Lazy::new(|| {
332-
let catcher = || client_generic().use_rustls_tls().build();
338+
let catcher = || {
339+
client_generic()
340+
.use_rustls_tls()
341+
.user_agent(super::REQWEST_RUSTLS_TLS_USER_AGENT)
342+
.build()
343+
};
333344

334345
// woah, an unwrap?!
335346
// It's OK. This is the same as what is happening in curl.
@@ -342,7 +353,11 @@ pub mod reqwest_be {
342353

343354
#[cfg(feature = "reqwest-default-tls")]
344355
static CLIENT_DEFAULT_TLS: Lazy<Client> = Lazy::new(|| {
345-
let catcher = || client_generic().build();
356+
let catcher = || {
357+
client_generic()
358+
.user_agent(super::REQWEST_DEFAULT_TLS_USER_AGENT)
359+
.build()
360+
};
346361

347362
// woah, an unwrap?!
348363
// It's OK. This is the same as what is happening in curl.

0 commit comments

Comments
 (0)