Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 287dbbe

Browse files
committed
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: 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?
2 parents b9d3d07 + 850bd5a commit 287dbbe

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function __toString()
6767
$cookies .= 'Set-Cookie: '.$cookie."\r\n";
6868
}
6969

70+
ksort($this->headerNames);
71+
7072
return parent::__toString().$cookies;
7173
}
7274

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ public function testMakeDisposition($disposition, $filename, $filenameFallback,
235235
$this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
236236
}
237237

238+
public function testToStringDoesntMessUpHeaders()
239+
{
240+
$headers = new ResponseHeaderBag();
241+
242+
$headers->set('Location', 'http://www.symfony.com');
243+
$headers->set('Content-type', 'text/html');
244+
245+
(string) $headers;
246+
247+
$allHeaders = $headers->allPreserveCase();
248+
$this->assertEquals(array('http://www.symfony.com'), $allHeaders['Location']);
249+
$this->assertEquals(array('text/html'), $allHeaders['Content-type']);
250+
}
251+
238252
public function provideMakeDisposition()
239253
{
240254
return array(

0 commit comments

Comments
 (0)