How would one decode a server response that is
1) transfer-encode: chunked 2) content-type: gzip
I need to do this manually and can't just use curl to send the request. I need to decode from the raw $string.
Here's a function that is supposed to unchunk a HTTP reponse (php):
function unchunkHttpResponse($str=null) {
if (!is_string($str) or strlen($str) < 1) { return false; }
$eol = "\r\n";
$add = strlen($eol);
$tmp = $str;
$str = '';
do {
$tmp = ltrim($tmp);
$pos = strpos($tmp, $eol);
if ($pos === false) { return false; }
$len = hexdec(substr($tmp,0,$pos));
if (!is_numeric($len) or $len < 0) { return false; }
$str .= substr($tmp, ($pos + $add), $len);
$tmp = substr($tmp, ($len + $pos + $add));
$check = trim($tmp);
} while(!empty($check));
unset($tmp);
return $str;
}
But it seems to not work with gzipped content (gzinflate is not in this snippet). I tried doing gzinflate on the returned content but that doesn't work at all.
Any ideas? Or how do gzip + transfer encoding chunked work together?
Thanks