Check for gzip in transfer-encoding header also.

This commit is contained in:
Ryan Coffman
2017-03-12 00:40:56 -08:00
parent 11b993bb2c
commit 559ecfab45

View File

@@ -4,7 +4,8 @@ use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use hyper::client::IntoUrl; use hyper::client::IntoUrl;
use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, ContentEncoding, Encoding, ContentLength}; use hyper::header::{Headers, ContentType, Location, Referer, UserAgent, Accept, ContentEncoding, Encoding, ContentLength,
TransferEncoding};
use hyper::method::Method; use hyper::method::Method;
use hyper::status::StatusCode; use hyper::status::StatusCode;
use hyper::version::HttpVersion; use hyper::version::HttpVersion;
@@ -409,13 +410,15 @@ impl Decoder {
if !check_gzip { if !check_gzip {
return Decoder::PlainText(res); return Decoder::PlainText(res);
} }
let mut is_gzip = {
let mut is_gzip = false; res.headers.get::<ContentEncoding>().map_or(false, |encs|{
match res.headers.get::<ContentEncoding>() { encs.contains(&Encoding::Gzip)
Some(encoding_types) => { }) ||
if encoding_types.contains(&Encoding::Gzip) { res.headers.get::<TransferEncoding>().map_or(false, |encs|{
is_gzip = true; encs.contains(&Encoding::Gzip)
} })
};
if is_gzip {
if let Some(content_length) = res.headers.get::<ContentLength>() { if let Some(content_length) = res.headers.get::<ContentLength>() {
if content_length.0 == 0 { if content_length.0 == 0 {
warn!("GZipped response with content-length of 0"); warn!("GZipped response with content-length of 0");
@@ -423,9 +426,6 @@ impl Decoder {
} }
} }
} }
_ => {}
}
if is_gzip { if is_gzip {
return Decoder::Gzip { return Decoder::Gzip {
status: res.status.clone(), status: res.status.clone(),