diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 328bf4913cb02..a2e9a33713a09 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -290,12 +290,8 @@ protected function computeCacheControlValue() } $header = $this->getCacheControlHeader(); - if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) { - return $header; - } - - // public if s-maxage is defined, private otherwise - if (!isset($this->cacheControl['s-maxage'])) { + // private, if public/private is not set, and this is not "no-cache", and s-maxage is not defined, + if (!isset($this->cacheControl['public']) && !isset($this->cacheControl['private']) && !isset($this->cacheControl['no-cache']) && !isset($this->cacheControl['s-maxage'])) { return $header.', private'; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index 96d9d55680d63..2ea241f4538b9 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php @@ -37,6 +37,10 @@ public function provideAllPreserveCase() array('fOo' => 'BAR'), array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')), ), + array( + array('fOo' => 'BAR', 'Cache-Control' => array('no-cache')), + array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')), + ), array( array('ETag' => 'xyzzy'), array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')), @@ -142,6 +146,15 @@ public function testReplace() $bag->replace(array('Cache-Control' => 'public')); $this->assertEquals('public', $bag->get('Cache-Control')); $this->assertTrue($bag->hasCacheControlDirective('public')); + + $bag = new ResponseHeaderBag(array('Etag' => 'aaaa')); + $this->assertEquals('private, must-revalidate', $bag->get('Cache-Control')); + $this->assertTrue($bag->hasCacheControlDirective('private')); + $this->assertTrue($bag->hasCacheControlDirective('must-revalidate')); + + $bag->replace(array()); + $this->assertEquals('no-cache', $bag->get('Cache-Control')); + $this->assertTrue($bag->hasCacheControlDirective('no-cache')); } public function testReplaceWithRemove() @@ -261,6 +274,14 @@ public function testToStringDoesntMessUpHeaders() $this->assertEquals(array('text/html'), $allHeaders['Content-type']); } + public function testEquality() + { + $headers = new ResponseHeaderBag(); + $anotherHeaders = new ResponseHeaderBag($headers->allPreserveCase()); + + $this->assertEquals($headers->allPreserveCase(), $anotherHeaders->allPreserveCase()); + } + public function provideMakeDisposition() { return array(