|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48929 [PATCH]?Double \r\n after HTTP headers when "header" context option is an array
Submitted: 2009-07-15 17:26 UTC Modified: 2009-07-20 10:55 UTC
From: david dot zuelke at bitextender dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
45 - 15 = ?
Subscribe to this entry?

 [2009-07-15 17:26 UTC] david dot zuelke at bitextender dot com
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('', 'rb', false, $context);

Expected result:
A \r\n after the last header, another \r\n to create a blank line, then 

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-15 17:48 UTC] david dot zuelke at bitextender dot com
 [2009-07-15 17:53 UTC] david dot zuelke at bitextender dot com
 [2009-07-20 10:54 UTC]
Automatic comment from SVN on behalf of jani
Log: Fixed bug #48929 (Double \r\n after HTTP headers when "header" context option is an array)
 [2009-07-20 10:55 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 05:01:28 2024 UTC