From 932751ea2c6a71f3f297d36228d4ac5d79cd91f0 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 28 Feb 2022 20:40:23 +0800 Subject: [PATCH] Add the user agent for http requests Signed-off-by: hi-rustin --- CONTRIBUTING.md | 2 +- Cargo.lock | 4 +++- download/Cargo.toml | 2 +- download/src/lib.rs | 6 ++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be753031df..2923fb87e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,7 +152,7 @@ APIs, we should behave well if we can. Producing the final release artifacts is a bit involved because of the way Rustup is distributed. The steps for a release are: -1. Update all `Cargo.toml` to have the new version +1. Update `Cargo.toml` and `download/Cargo.toml`to have the same new version (optionally make a commit) 2. Run `cargo build` and review `Cargo.lock` changes if all looks well, make a commit diff --git a/Cargo.lock b/Cargo.lock index 2d5d5942e6..7d83c34e4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "addr2line" version = "0.14.1" @@ -568,7 +570,7 @@ dependencies = [ [[package]] name = "download" -version = "0.6.9" +version = "1.24.3" dependencies = [ "anyhow", "curl", diff --git a/download/Cargo.toml b/download/Cargo.toml index bb35a72f99..3d29b250e4 100644 --- a/download/Cargo.toml +++ b/download/Cargo.toml @@ -4,7 +4,7 @@ authors = ["Brian Anderson "] edition = "2021" license = "MIT/Apache-2.0" name = "download" -version = "0.6.9" +version = "1.24.3" [features] diff --git a/download/src/lib.rs b/download/src/lib.rs index fb95eb72e2..926aa1ff86 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -10,6 +10,10 @@ use url::Url; mod errors; pub use crate::errors::*; +/// User agent header value for HTTP request. +/// See: https://github.com/rust-lang/rustup/issues/2860. +const USER_AGENT: &str = concat!("rustup/", env!("CARGO_PKG_VERSION")); + #[derive(Debug, Copy, Clone)] pub enum Backend { Curl, @@ -164,6 +168,7 @@ pub mod curl { handle.url(url.as_ref())?; handle.follow_location(true)?; + handle.useragent(super::USER_AGENT)?; if resume_from > 0 { handle.resume_from(resume_from)?; @@ -303,6 +308,7 @@ pub mod reqwest_be { fn client_generic() -> ClientBuilder { Client::builder() .gzip(false) + .user_agent(super::USER_AGENT) .proxy(Proxy::custom(env_proxy)) .timeout(Duration::from_secs(30)) }