m2php
m2php copied to clipboard
Unable To Send Multiple of the Same Header Type
Tool.php (see following code block or line 25-29) incorrectly assumes that only one of a certain header type will be sent per response. This is mostly true, except in the case of cookies. Cookies use the Set-Cookie header. eg, "Set-Cookie: name=value; Expires=Wed, 01-Apr-2021 00:00:00 GMT".
$headers['Content-Length'] = strlen($body);
$hd = "";
foreach($headers as $k => $v) {
$hd .= sprintf("%s: %s\r\n", $k, $v);
}
However, setting multiple cookies within one request using the current $headers scheme ($headers[$header_name] = $header_value) will not work.
I suggest revising this so that $headers is no longer an associative array, and is instead just an array of strings. These strings will be the fully-written header, identical to the argument one would pass to the header() function, eg, "Set-Cookie: name=value".
As a temporary workaround for those that run into this issue,
$headers['Set-Cookie'] = "name=value;\r\nSet-Cookie: name2=value";
http://en.wikipedia.org/wiki/HTTP_cookie#Setting_a_cookie http://php.net/manual/en/function.header.php
An actual implementation of my suggested revision can be found here, lines 25-29: https://github.com/liamzdenek/m2php/blob/ab29f2f326b6ed111cc211d8d58c2921794810ea/framework/Mongrel2/Tool.php#L25
Thanks for your investigation!
I'm not sure if this triggers some behaviour that I have a faint memory of - I'll try to check.