Add support for transfer-encoding chunked (Stream Client)
This commit is contained in:
parent
4fdd2913ae
commit
d6984c426c
21
vendor/PicoFeed/Clients/Stream.php
vendored
21
vendor/PicoFeed/Clients/Stream.php
vendored
@ -57,10 +57,31 @@ class Stream extends \PicoFeed\Client
|
|||||||
|
|
||||||
fclose($stream);
|
fclose($stream);
|
||||||
|
|
||||||
|
if (isset($headers['Transfer-Encoding']) && $headers['Transfer-Encoding'] === 'chunked') {
|
||||||
|
$body = $this->decodeChunked($body);
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'body' => $body,
|
'body' => $body,
|
||||||
'headers' => $headers
|
'headers' => $headers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function decodeChunked($str)
|
||||||
|
{
|
||||||
|
for ($result = ''; ! empty($str); $str = trim($str)) {
|
||||||
|
|
||||||
|
// Get the chunk length
|
||||||
|
$pos = strpos($str, "\r\n");
|
||||||
|
$len = hexdec(substr($str, 0, $pos));
|
||||||
|
|
||||||
|
// Append the chunk to the result
|
||||||
|
$result .= substr($str, $pos + 2, $len);
|
||||||
|
$str = substr($str, $pos + 2 + $len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user