merged branch SamsonIT/fixedMessedUpHeaders (PR #7189)
This PR was squashed before being merged into the 2.2 branch (closes #7189).
Commits
-------
850bd5a
[HttpFoundation] Fixed messed up headers
Discussion
----------
[HttpFoundation] Fixed messed up headers
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
I ran into this when somewhere in our code the Response object was cast into a string. After that, when send()'ing the Response, the headers would be all mixed up. This is because the __toString in HeaderBag ksorts the headers, while the __toString in ResponseHeaderBag doesn't ksort the corresponding headerNames. This patch ksorts that one as well.
allPreserveCase() is new to 2.2, so this bug doesn't seem to affect earlier versions.
To be exact, this is where it got introduced: https://github.com/symfony/symfony/commit/63a228c45613bb
---------------------------------------------------------------------------
by Burgov at 2013-02-26T09:27:20Z
B.t.w. another option was to ksort a copy of the headers array in the ResponseBag and leaving the actual thing as-is. Not sure which one would be the best option?
This commit is contained in:
commit
287dbbe99d
@ -67,6 +67,8 @@ class ResponseHeaderBag extends HeaderBag
|
||||
$cookies .= 'Set-Cookie: '.$cookie."\r\n";
|
||||
}
|
||||
|
||||
ksort($this->headerNames);
|
||||
|
||||
return parent::__toString().$cookies;
|
||||
}
|
||||
|
||||
|
@ -235,6 +235,20 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
|
||||
}
|
||||
|
||||
public function testToStringDoesntMessUpHeaders()
|
||||
{
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$headers->set('Location', 'http://www.symfony.com');
|
||||
$headers->set('Content-type', 'text/html');
|
||||
|
||||
(string) $headers;
|
||||
|
||||
$allHeaders = $headers->allPreserveCase();
|
||||
$this->assertEquals(array('http://www.symfony.com'), $allHeaders['Location']);
|
||||
$this->assertEquals(array('text/html'), $allHeaders['Content-type']);
|
||||
}
|
||||
|
||||
public function provideMakeDisposition()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user