Skip to content
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

Don't set a user-agent header by default. #540

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## Unreleased

- Reqwest no longer sets a User-Agent header by default. If you are interacting
with services which require a user agent, you will need to set one manually.

## v0.9.18

- Fix `Cookie` headers to no longer send as percent-encoded (instead, exactly as sent by the server).
Expand Down
5 changes: 0 additions & 5 deletions src/async_impl/client.rs
Expand Up @@ -19,7 +19,6 @@ use header::{
RANGE,
REFERER,
TRANSFER_ENCODING,
USER_AGENT,
};
use http::Uri;
use hyper::client::ResponseFuture;
Expand All @@ -41,9 +40,6 @@ use {Certificate, Identity};
#[cfg(feature = "tls")]
use ::tls::TlsBackend;

static DEFAULT_USER_AGENT: &'static str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

/// An asynchronous `Client` to make Requests with.
///
/// The Client has various configuration values to tweak, but the defaults
Expand Down Expand Up @@ -94,7 +90,6 @@ impl ClientBuilder {
/// This is the same as `Client::builder()`.
pub fn new() -> ClientBuilder {
let mut headers: HeaderMap<HeaderValue> = HeaderMap::with_capacity(2);
headers.insert(USER_AGENT, HeaderValue::from_static(DEFAULT_USER_AGENT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just removing this, can the logic be moved into its own default_useragent method (similarly to what we do for default_headers)?

headers.insert(ACCEPT, HeaderValue::from_str(mime::STAR_STAR.as_ref()).expect("unable to parse mime"));

ClientBuilder {
Expand Down
4 changes: 0 additions & 4 deletions tests/async.rs
Expand Up @@ -63,7 +63,6 @@ fn multipart() {
request: format!("\
POST /multipart/1 HTTP/1.1\r\n\
content-type: multipart/form-data; boundary={}\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -105,7 +104,6 @@ fn request_timeout() {
let server = server! {
request: b"\
GET /slow HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -145,7 +143,6 @@ fn response_timeout() {
let server = server! {
request: b"\
GET /slow HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -200,7 +197,6 @@ fn gzip_case(response_size: usize, chunk_size: usize) {
let server = server! {
request: b"\
GET /gzip HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down
13 changes: 0 additions & 13 deletions tests/client.rs
Expand Up @@ -10,7 +10,6 @@ fn test_response_text() {
let server = server! {
request: b"\
GET /text HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -41,7 +40,6 @@ fn test_response_non_utf_8_text() {
let server = server! {
request: b"\
GET /text HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -74,7 +72,6 @@ fn test_response_copy_to() {
let server = server! {
request: b"\
GET /1 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -106,7 +103,6 @@ fn test_get() {
let server = server! {
request: b"\
GET /1 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -140,7 +136,6 @@ fn test_post() {
request: b"\
POST /2 HTTP/1.1\r\n\
content-length: 5\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -179,7 +174,6 @@ fn test_post_form() {
POST /form HTTP/1.1\r\n\
content-type: application/x-www-form-urlencoded\r\n\
content-length: 24\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -214,7 +208,6 @@ fn test_error_for_status_4xx() {
let server = server! {
request: b"\
GET /1 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -243,7 +236,6 @@ fn test_error_for_status_5xx() {
let server = server! {
request: b"\
GET /1 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -277,7 +269,6 @@ fn test_default_headers() {
let server = server! {
request: b"\
GET /1 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: a=b;c=d\r\n\
accept-encoding: gzip\r\n\
Expand All @@ -303,7 +294,6 @@ fn test_default_headers() {
let server = server! {
request: b"\
GET /2 HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: a=b;c=d\r\n\
accept-encoding: gzip\r\n\
Expand Down Expand Up @@ -340,7 +330,6 @@ fn test_override_default_headers() {
request: b"\
GET /3 HTTP/1.1\r\n\
authorization: secret\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -373,7 +362,6 @@ fn test_appended_headers_not_overwritten() {
GET /4 HTTP/1.1\r\n\
accept: application/json\r\n\
accept: application/json+hal\r\n\
user-agent: $USERAGENT\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
\r\n\
Expand Down Expand Up @@ -407,7 +395,6 @@ fn test_appended_headers_not_overwritten() {
GET /4 HTTP/1.1\r\n\
accept: application/json\r\n\
accept: application/json+hal\r\n\
user-agent: $USERAGENT\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
\r\n\
Expand Down
13 changes: 0 additions & 13 deletions tests/cookie.rs
Expand Up @@ -11,7 +11,6 @@ fn cookie_response_accessor() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -86,7 +85,6 @@ fn cookie_store_simple() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -105,7 +103,6 @@ fn cookie_store_simple() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: key=val\r\n\
accept-encoding: gzip\r\n\
Expand All @@ -130,7 +127,6 @@ fn cookie_store_overwrite_existing() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -149,7 +145,6 @@ fn cookie_store_overwrite_existing() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: key=val\r\n\
accept-encoding: gzip\r\n\
Expand All @@ -169,7 +164,6 @@ fn cookie_store_overwrite_existing() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: key=val2\r\n\
accept-encoding: gzip\r\n\
Expand All @@ -194,7 +188,6 @@ fn cookie_store_max_age() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -213,7 +206,6 @@ fn cookie_store_max_age() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -237,7 +229,6 @@ fn cookie_store_expires() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -256,7 +247,6 @@ fn cookie_store_expires() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -280,7 +270,6 @@ fn cookie_store_path() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -299,7 +288,6 @@ fn cookie_store_path() {
let server = server! {
request: b"\
GET / HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -317,7 +305,6 @@ fn cookie_store_path() {
let server = server! {
request: b"\
GET /subpath HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
cookie: key=val\r\n\
accept-encoding: gzip\r\n\
Expand Down
5 changes: 0 additions & 5 deletions tests/gzip.rs
Expand Up @@ -31,7 +31,6 @@ fn test_gzip_response() {
let server = server! {
request: b"\
GET /gzip HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand All @@ -54,7 +53,6 @@ fn test_gzip_empty_body() {
let server = server! {
request: b"\
HEAD /gzip HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -85,7 +83,6 @@ fn test_gzip_invalid_body() {
let server = server! {
request: b"\
GET /gzip HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -114,7 +111,6 @@ fn test_accept_header_is_not_changed_if_set() {
request: b"\
GET /accept HTTP/1.1\r\n\
accept: application/json\r\n\
user-agent: $USERAGENT\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
\r\n\
Expand Down Expand Up @@ -143,7 +139,6 @@ fn test_accept_encoding_header_is_not_changed_if_set() {
request: b"\
GET /accept-encoding HTTP/1.1\r\n\
accept-encoding: identity\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
host: $HOST\r\n\
\r\n\
Expand Down
2 changes: 0 additions & 2 deletions tests/multipart.rs
Expand Up @@ -23,7 +23,6 @@ fn text_part() {
POST /multipart/1 HTTP/1.1\r\n\
content-type: multipart/form-data; boundary={}\r\n\
content-length: 125\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down Expand Up @@ -72,7 +71,6 @@ fn file() {
POST /multipart/2 HTTP/1.1\r\n\
content-type: multipart/form-data; boundary={}\r\n\
content-length: {}\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
Expand Down
3 changes: 0 additions & 3 deletions tests/proxy.rs
Expand Up @@ -8,7 +8,6 @@ fn http_proxy() {
let server = server! {
request: b"\
GET http://hyper.rs/prox HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
host: hyper.rs\r\n\
Expand Down Expand Up @@ -43,7 +42,6 @@ fn http_proxy_basic_auth() {
let server = server! {
request: b"\
GET http://hyper.rs/prox HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
proxy-authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\
Expand Down Expand Up @@ -83,7 +81,6 @@ fn http_proxy_basic_auth_parsed() {
let server = server! {
request: b"\
GET http://hyper.rs/prox HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
accept-encoding: gzip\r\n\
proxy-authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\
Expand Down