Added test to check the Accept-Encoding is not changed if already set
This commit is contained in:
@@ -14,6 +14,7 @@ fn test_get() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
",
|
",
|
||||||
response: b"\
|
response: b"\
|
||||||
@@ -47,6 +48,7 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
Content-Length: 0\r\n\
|
Content-Length: 0\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
", code),
|
", code),
|
||||||
@@ -64,6 +66,7 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
Referer: http://$HOST/{}\r\n\
|
Referer: http://$HOST/{}\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
", code),
|
", code),
|
||||||
@@ -94,6 +97,7 @@ fn test_redirect_307_and_308_tries_to_post_again() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
Content-Length: 5\r\n\
|
Content-Length: 5\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
Hello\
|
Hello\
|
||||||
@@ -112,6 +116,7 @@ fn test_redirect_307_and_308_tries_to_post_again() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
Referer: http://$HOST/{}\r\n\
|
Referer: http://$HOST/{}\r\n\
|
||||||
Content-Length: 5\r\n\
|
Content-Length: 5\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
@@ -145,6 +150,7 @@ fn test_redirect_307_does_not_try_if_reader_cannot_reset() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
Transfer-Encoding: chunked\r\n\
|
Transfer-Encoding: chunked\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
5\r\n\
|
5\r\n\
|
||||||
@@ -177,6 +183,7 @@ fn test_redirect_policy_can_return_errors() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
",
|
",
|
||||||
response: b"\
|
response: b"\
|
||||||
@@ -203,6 +210,7 @@ fn test_redirect_policy_can_stop_redirects_without_an_error() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
",
|
",
|
||||||
response: b"\
|
response: b"\
|
||||||
@@ -232,6 +240,7 @@ fn test_accept_header_is_not_changed_if_set() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
Accept: application/json\r\n\
|
Accept: application/json\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
",
|
",
|
||||||
response: b"\
|
response: b"\
|
||||||
@@ -251,6 +260,36 @@ fn test_accept_header_is_not_changed_if_set() {
|
|||||||
assert_eq!(res.status(), &reqwest::StatusCode::Ok);
|
assert_eq!(res.status(), &reqwest::StatusCode::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_accept_encoding_header_is_not_changed_if_set() {
|
||||||
|
let server = server! {
|
||||||
|
request: b"\
|
||||||
|
GET /accept-encoding HTTP/1.1\r\n\
|
||||||
|
Host: $HOST\r\n\
|
||||||
|
Accept-Encoding: identity\r\n\
|
||||||
|
User-Agent: $USERAGENT\r\n\
|
||||||
|
Accept: */*\r\n\
|
||||||
|
\r\n\
|
||||||
|
",
|
||||||
|
response: b"\
|
||||||
|
HTTP/1.1 200 OK\r\n\
|
||||||
|
Server: test-accept-encoding\r\n\
|
||||||
|
Content-Length: 0\r\n\
|
||||||
|
\r\n\
|
||||||
|
"
|
||||||
|
};
|
||||||
|
let client = reqwest::Client::new().unwrap();
|
||||||
|
|
||||||
|
let res = client.get(&format!("http://{}/accept-encoding", server.addr()))
|
||||||
|
.header(reqwest::header::AcceptEncoding(
|
||||||
|
vec![reqwest::header::qitem(reqwest::header::Encoding::Identity)]
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(res.status(), &reqwest::StatusCode::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gzip_response() {
|
fn test_gzip_response() {
|
||||||
let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap();
|
let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap();
|
||||||
@@ -276,6 +315,7 @@ fn test_gzip_response() {
|
|||||||
Host: $HOST\r\n\
|
Host: $HOST\r\n\
|
||||||
User-Agent: $USERAGENT\r\n\
|
User-Agent: $USERAGENT\r\n\
|
||||||
Accept: */*\r\n\
|
Accept: */*\r\n\
|
||||||
|
Accept-Encoding: gzip\r\n\
|
||||||
\r\n\
|
\r\n\
|
||||||
",
|
",
|
||||||
response: response
|
response: response
|
||||||
@@ -290,4 +330,4 @@ fn test_gzip_response() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(body, "test request");
|
assert_eq!(body, "test request");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user