zendframework/zend-http

\Zend\Http\Response mbstring.func_overload + utf8 + transfer encoding chunked = corrupt http response parser.

Opened this issue · 1 comments

GeeH commented

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7653
User: @olegserov
Created On: 2015-12-19T21:04:21Z
Updated At: 2016-02-13T15:33:40Z
Body
I'm using mbstring with mbstring.func_overload = 6 (http://php.net/manual/en/mbstring.overload.php)
I was using zend http client to make http requests. One of my requests failed. This error disappears when I'm switching from Zend\Http\Client\Adapter\Socket to Zend\Http\Client\Adapter\Curl, but anyway it is a nasty error with popular mbstring module. I've debugged it to this simple test case.
As you can see when you use utf8 you get a longer content than when you are using 8bit encoding.
This is what it forgets to remove "\r\n0\r\n\r\n"
Here is the request: log.txt

$responseRaw = file_get_contents('log.txt');

assert(ini_get('mbstring.func_overload') == 6);

mb_internal_encoding('8bit');
$res = \Zend\Http\Response::fromString($responseRaw);
$_8bit = $res->getBody();

mb_internal_encoding('utf8');
$res = \Zend\Http\Response::fromString($responseRaw);
$_utf8 = $res->getBody();

echo "8bit=" . md5($_8bit), "; len=", mb_strlen($_8bit, "8bit"), "\n";
echo "utf8=" . md5($_utf8), "; len=", mb_strlen($_utf8, "8bit"),"\n";
// Outputs
// 8bit=c4c2fe78e727b96adbb1f4cbd1187ff2; len=35001
// utf8=ec9b49502969cfd63e382014a29c3e5f; len=35008

This repository has been closed and moved to laminas/laminas-http; a new issue has been opened at laminas/laminas-http#17.