ID: 48929 Comment by: david dot zuelke at bitextender dot com Reported By: david dot zuelke at bitextender dot com Status: Open Bug Type: Streams related Operating System: Mac OS X 10.5.7 PHP Version: 5.3.0 New Comment:
http://article.gmane.org/gmane.comp.php.devel/57937 Previous Comments: ------------------------------------------------------------------------ [2009-07-15 17:48:13] david dot zuelke at bitextender dot com Patch: http://pastie.org/547066 ------------------------------------------------------------------------ [2009-07-15 17:26:50] david dot zuelke at bitextender dot com Description: ------------ When making an HTTP request through the HTTP stream wrapper, there will be a duplicate \r\n sequence separating header lines and request body if the HTTP stream context option "header" is an array (which is possible since 5.2.10; it had to be a string with the individual, \r\n-separated header lines before that). As a result, the last two bytes of the request will never reach the destination server, as it closes the connection when reaching the indicated Content-Length (which is off by two bytes due to the extra \r\n). The HTTP specification explicitly states that one \r\n sequence should be used to separate the last (\r\n-terminated) header line from the request body. All is fine when supplying headers as a string instead of an array. Reproduce code: --------------- $context = stream_context_create(array('http' => array('header' => array('X-Foo: bar', 'Content-Type: text/plain'), 'method' => 'POST', 'content' => 'ohai'))); $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context); Expected result: ---------------- A \r\n after the last header, another \r\n to create a blank line, then "ohai" Actual result: -------------- A \r\n after the last header, then \r\n twice which creates two blank lines, then "oh". "ai" never arrives as the Content-Length is reached. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48929&edit=1