Forráskód Böngészése

[HttpFoundation] updated ResponseHeaderBag to compute Cache-Control whenever any of the headers it considers changes

Kris Wallsmith 14 éve
szülő
commit
a0bae94f88

+ 1 - 1
src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

@@ -54,7 +54,7 @@ class ResponseHeaderBag extends HeaderBag
         parent::set($key, $values, $replace);
 
         // ensure the cache-control header has sensible defaults
-        if ('cache-control' === strtr(strtolower($key), '_', '-')) {
+        if (in_array(strtr(strtolower($key), '_', '-'), array('cache-control', 'etag', 'last-modified', 'expires'))) {
             $computed = $this->computeCacheControlValue();
             $this->headers['cache-control'] = array($computed);
             $this->computedCacheControl = $this->parseCacheControl($computed);

+ 4 - 0
tests/Symfony/Tests/Component/HttpFoundation/ResponseHeaderBagTest.php

@@ -57,5 +57,9 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
 
         $bag = new ResponseHeaderBag(array('cache-control' => 'public, max-age=100'));
         $this->assertEquals('max-age=100, public', $bag->get('Cache-Control'));
+
+        $bag = new ResponseHeaderBag();
+        $bag->set('Last-Modified', 'abcde');
+        $this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
     }
 }