From 1a01a1311d367424e0cb42086a5191173f82b006 Mon Sep 17 00:00:00 2001 From: Ryan Coffman Date: Mon, 13 Mar 2017 16:30:55 -0700 Subject: [PATCH] Added test to check the Accept-Encoding is not changed if already set --- tests/client.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/client.rs b/tests/client.rs index 15d53a6..7af28a6 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -14,6 +14,7 @@ fn test_get() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ \r\n\ ", response: b"\ @@ -47,6 +48,7 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ Content-Length: 0\r\n\ \r\n\ ", code), @@ -64,6 +66,7 @@ fn test_redirect_301_and_302_and_303_changes_post_to_get() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ Referer: http://$HOST/{}\r\n\ \r\n\ ", code), @@ -94,6 +97,7 @@ fn test_redirect_307_and_308_tries_to_post_again() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ Content-Length: 5\r\n\ \r\n\ Hello\ @@ -112,6 +116,7 @@ fn test_redirect_307_and_308_tries_to_post_again() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ Referer: http://$HOST/{}\r\n\ Content-Length: 5\r\n\ \r\n\ @@ -145,6 +150,7 @@ fn test_redirect_307_does_not_try_if_reader_cannot_reset() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ Transfer-Encoding: chunked\r\n\ \r\n\ 5\r\n\ @@ -177,6 +183,7 @@ fn test_redirect_policy_can_return_errors() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ \r\n\ ", response: b"\ @@ -203,6 +210,7 @@ fn test_redirect_policy_can_stop_redirects_without_an_error() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ \r\n\ ", response: b"\ @@ -232,6 +240,7 @@ fn test_accept_header_is_not_changed_if_set() { Host: $HOST\r\n\ Accept: application/json\r\n\ User-Agent: $USERAGENT\r\n\ + Accept-Encoding: gzip\r\n\ \r\n\ ", response: b"\ @@ -251,6 +260,36 @@ fn test_accept_header_is_not_changed_if_set() { 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] fn test_gzip_response() { let mut encoder = ::libflate::gzip::Encoder::new(Vec::new()).unwrap(); @@ -276,6 +315,7 @@ fn test_gzip_response() { Host: $HOST\r\n\ User-Agent: $USERAGENT\r\n\ Accept: */*\r\n\ + Accept-Encoding: gzip\r\n\ \r\n\ ", response: response @@ -290,4 +330,4 @@ fn test_gzip_response() { }; assert_eq!(body, "test request"); -} \ No newline at end of file +}