From 65ce43da210ac94ad639a127e0aa7c58c80f573e Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Thu, 22 Oct 2015 00:09:29 +0200 Subject: [PATCH 1/3] leave cache-control no-cache as is (#16171) --- .../Component/HttpFoundation/ResponseHeaderBag.php | 8 ++------ .../HttpFoundation/Tests/ResponseHeaderBagTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 328bf4913cb02..3140110fc3257 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 s-maxage is not defined, public/private is not set, and this is not "no-cache" + if (!isset($this->cacheControl['s-maxage']) && !isset($this->cacheControl['public']) && !isset($this->cacheControl['private']) && !isset($this->cacheControl['no-cache'])) { return $header.', private'; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index 96d9d55680d63..d31e9635b0129 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() From 949b1c258555d4cee152b785d0eab7a59931e3ba Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Thu, 22 Oct 2015 00:17:02 +0200 Subject: [PATCH 2/3] reorganize checks to cover usuall cases first --- src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 3140110fc3257..a2e9a33713a09 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -290,8 +290,8 @@ protected function computeCacheControlValue() } $header = $this->getCacheControlHeader(); - // private, if s-maxage is not defined, public/private is not set, and this is not "no-cache" - if (!isset($this->cacheControl['s-maxage']) && !isset($this->cacheControl['public']) && !isset($this->cacheControl['private']) && !isset($this->cacheControl['no-cache'])) { + // 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'; } From e4d8c0d893162a34c1eb5dbfdc367b41f64d65f9 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Thu, 22 Oct 2015 08:57:03 +0200 Subject: [PATCH 3/3] add equality test to create ResponseHeaderBag --- .../HttpFoundation/Tests/ResponseHeaderBagTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index d31e9635b0129..2ea241f4538b9 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php @@ -274,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(