fix panic from Gzip reading an empty stream

Closes #82
This commit is contained in:
Sean McArthur
2017-05-05 11:30:01 -07:00
parent 76921efbfb
commit 3cc4d654a3
2 changed files with 180 additions and 39 deletions

View File

@@ -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();
}