Index: Zend/Http/Client/Adapter/Socket.php =================================================================== --- Zend/Http/Client/Adapter/Socket.php (revision 113) +++ Zend/Http/Client/Adapter/Socket.php (working copy) @@ -262,15 +262,14 @@ $chunksize = hexdec($chunksize); // Read chunk - $left_to_read = $chunksize; - while ($left_to_read > 0) { - $line = @fread($this->socket, $left_to_read); + $read_to = ftell($this->socket) + $chunksize; + while ($read_to > ftell($this->socket)) { + $line = @fread($this->socket, $read_to - ftell($this->socket)); if ($line === false || strlen($line) === 0) { break; } else { $chunk .= $line; - $left_to_read -= strlen($line); } // Break if the connection ended prematurely @@ -290,13 +289,14 @@ } elseif (isset($headers['content-length'])) { $left_to_read = $headers['content-length']; $chunk = ''; - while ($left_to_read > 0) { - $chunk = @fread($this->socket, $left_to_read); + + $read_to = ftell($this->socket) + $left_to_read; + while ($read_to > ftell($this->socket)) { + $chunk = @fread($this->socket, $read_to - ftell($this->socket)); if ($chunk === false || strlen($chunk) === 0) { break; } else { - $left_to_read -= strlen($chunk); $response .= $chunk; } Index: Zend/Http/Response.php =================================================================== --- Zend/Http/Response.php (revision 108) +++ Zend/Http/Response.php (working copy) @@ -558,10 +558,21 @@ } $length = hexdec(trim($m[1])); - $cut = strlen($m[0]); + + if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { + $cut = mb_strlen($m[0], 'ascii'); + } else { + $cut = strlen($m[0]); + } - $decBody .= substr($body, $cut, $length); - $body = substr($body, $cut + $length + 2); + if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { + $decBody .= mb_substr($body, $cut, $length, 'ascii'); + $body = mb_substr($body, $cut + $length + 2, -1, 'ascii'); + } + else { + $decBody .= substr($body, $cut, $length); + $body = substr($body, $cut + $length + 2); + } } return $decBody;