From b445a47c35898ccf0c0fb01ca272a42d0698b5d2 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Tue, 26 Feb 2013 09:53:49 +0100 Subject: [PATCH 1/2] created test demonstrating how calling __toString on the ResponseHeaderBag (triggered by a __toString on Response) causes the response headers to get messed up --- .../HttpFoundation/Tests/ResponseHeaderBagTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index fd163d197d206..c3dd9a27fc719 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php @@ -235,6 +235,20 @@ public function testMakeDisposition($disposition, $filename, $filenameFallback, $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( From 2b38a6daad0d80877fe9aa96a1b9853ed0683b62 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Tue, 26 Feb 2013 09:55:46 +0100 Subject: [PATCH 2/2] fixed __toString messing up the response headers --- src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 531e003fb7bff..f52f048875f2c 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -67,6 +67,8 @@ public function __toString() $cookies .= 'Set-Cookie: '.$cookie."\r\n"; } + ksort($this->headerNames); + return parent::__toString().$cookies; }