From d6984c426cdded53279683c5909221ce519c9088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Tue, 12 Nov 2013 22:31:04 -0500 Subject: [PATCH] Add support for transfer-encoding chunked (Stream Client) --- vendor/PicoFeed/Clients/Stream.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vendor/PicoFeed/Clients/Stream.php b/vendor/PicoFeed/Clients/Stream.php index 1a6b241..eaa610f 100644 --- a/vendor/PicoFeed/Clients/Stream.php +++ b/vendor/PicoFeed/Clients/Stream.php @@ -57,10 +57,31 @@ class Stream extends \PicoFeed\Client fclose($stream); + if (isset($headers['Transfer-Encoding']) && $headers['Transfer-Encoding'] === 'chunked') { + $body = $this->decodeChunked($body); + } + return array( 'status' => $status, 'body' => $body, '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; + } } \ No newline at end of file