From a2c8660f27162e3a7d61bb7588fb0ea6a6d96b9d Mon Sep 17 00:00:00 2001 From: Gennady Kovshenin Date: Sun, 11 Feb 2018 01:00:09 +0500 Subject: [PATCH] Add support for various deflate compression levels Different compression levels yield a specific second byte in the magic header for the deflate encoding. All of them can be decoded by the same functions without any issues. Let them through, as they've been seen in the wild. Fixes #301 --- src/Requests.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Requests.php b/src/Requests.php index 63b1375fa..5b5f642b3 100644 --- a/src/Requests.php +++ b/src/Requests.php @@ -823,7 +823,9 @@ public static function flatten($array) { * @return string Decompressed string */ public static function decompress($data) { - if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") { + // All valid deflate, gzip header magic markers + $valid_magic = array("\x1f\x8b", "\x78\x01", "\x78\x5e", "\x78\x9c", "\x78\xda"); + if (!in_array(substr($data, 0, 2), $valid_magic)) { // Not actually compressed. Probably cURL ruining this for us. return $data; }