@@ -344,3 +344,62 @@ fn test_gzip_response() {
|
||||
|
||||
assert_eq!(body, "test request");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gzip_empty_body() {
|
||||
let server = server! {
|
||||
request: b"\
|
||||
HEAD /gzip HTTP/1.1\r\n\
|
||||
Host: $HOST\r\n\
|
||||
User-Agent: $USERAGENT\r\n\
|
||||
Accept: */*\r\n\
|
||||
Accept-Encoding: gzip\r\n\
|
||||
\r\n\
|
||||
",
|
||||
response: b"\
|
||||
HTTP/1.1 200 OK\r\n\
|
||||
Server: test-accept\r\n\
|
||||
Content-Encoding: gzip\r\n\
|
||||
Content-Length: 100\r\n\
|
||||
\r\n"
|
||||
};
|
||||
|
||||
let client = reqwest::Client::new().unwrap();
|
||||
let mut res = client.head(&format!("http://{}/gzip", server.addr()))
|
||||
.send()
|
||||
.unwrap();
|
||||
|
||||
let mut body = ::std::string::String::new();
|
||||
res.read_to_string(&mut body).unwrap();
|
||||
|
||||
assert_eq!(body, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gzip_invalid_body() {
|
||||
let server = server! {
|
||||
request: b"\
|
||||
GET /gzip HTTP/1.1\r\n\
|
||||
Host: $HOST\r\n\
|
||||
User-Agent: $USERAGENT\r\n\
|
||||
Accept: */*\r\n\
|
||||
Accept-Encoding: gzip\r\n\
|
||||
\r\n\
|
||||
",
|
||||
response: b"\
|
||||
HTTP/1.1 200 OK\r\n\
|
||||
Server: test-accept\r\n\
|
||||
Content-Encoding: gzip\r\n\
|
||||
Content-Length: 100\r\n\
|
||||
\r\n\
|
||||
0"
|
||||
};
|
||||
|
||||
let mut res = reqwest::get(&format!("http://{}/gzip", server.addr()))
|
||||
.unwrap();
|
||||
// this tests that the request.send() didn't error, but that the error
|
||||
// is in reading the body
|
||||
|
||||
let mut body = ::std::string::String::new();
|
||||
res.read_to_string(&mut body).unwrap_err();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user