php - Decoding HTTP chunked + gzipped content -
how 1 decode server response
1) transfer-encode: chunked 2) content-type: gzip
i need manually , can't use curl send request. need decode raw $string.
here's function supposed unchunk 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 = ''; { $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 seems not work gzipped content (gzinflate not in snippet). tried doing gzinflate on returned content doesn't work @ all.
any ideas? or how gzip + transfer encoding chunked work together?
thanks
could start verifying function indeed aggregates chunked response trying against text response. i'm not proficient in php can't sure if function work, gzipped response binary, wonder if concatenating string ok thing do. , explain why need "decode raw $string"? why using client proven handle http details properly, , inflating whatever returns not working you?
Comments
Post a Comment