Skip to content

Commit

Permalink
[HttpFoundation] added private by default when setting Cache-Control …
Browse files Browse the repository at this point in the history
…to no-cache
  • Loading branch information
fabpot committed Jun 22, 2016
1 parent a151681 commit 2954236
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Response.php
Expand Up @@ -307,7 +307,7 @@ public function prepare(Request $request)
}

// Check if we need to send extra expire info headers
if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
if ('1.0' == $this->getProtocolVersion() && false !== strpos($this->headers->get('Cache-Control'), 'no-cache')) {
$this->headers->set('pragma', 'no-cache');
$this->headers->set('expires', -1);
}
Expand Down
2 changes: 1 addition & 1 deletion ResponseHeaderBag.php
Expand Up @@ -281,7 +281,7 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '')
protected function computeCacheControlValue()
{
if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
return 'no-cache';
return 'no-cache, private';
}

if (!$this->cacheControl) {
Expand Down
9 changes: 9 additions & 0 deletions Tests/HeaderBagTest.php
Expand Up @@ -171,6 +171,15 @@ public function testCacheControlDirectiveOverrideWithReplace()
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
}

public function testCacheControlClone()
{
$headers = array('foo' => 'bar');
$bag1 = new HeaderBag($headers);
$bag2 = new HeaderBag($bag1->all());

$this->assertEquals($bag1->all(), $bag2->all());
}

public function testGetIterator()
{
$headers = array('foo' => 'bar', 'hello' => 'world', 'third' => 'charm');
Expand Down
28 changes: 18 additions & 10 deletions Tests/ResponseHeaderBagTest.php
Expand Up @@ -34,39 +34,39 @@ public function provideAllPreserveCase()
return array(
array(
array('fOo' => 'BAR'),
array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')),
array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache, private')),
),
array(
array('ETag' => 'xyzzy'),
array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')),
),
array(
array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='),
array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache')),
array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache, private')),
),
array(
array('P3P' => 'CP="CAO PSA OUR"'),
array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache')),
array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache, private')),
),
array(
array('WWW-Authenticate' => 'Basic realm="WallyWorld"'),
array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache')),
array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache, private')),
),
array(
array('X-UA-Compatible' => 'IE=edge,chrome=1'),
array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache')),
array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache, private')),
),
array(
array('X-XSS-Protection' => '1; mode=block'),
array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache')),
array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache, private')),
),
);
}

public function testCacheControlHeader()
{
$bag = new ResponseHeaderBag(array());
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));

$bag = new ResponseHeaderBag(array('Cache-Control' => 'public'));
Expand Down Expand Up @@ -111,6 +111,14 @@ public function testCacheControlHeader()
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
}

public function testCacheControlClone()
{
$headers = array('foo' => 'bar');
$bag1 = new ResponseHeaderBag($headers);
$bag2 = new ResponseHeaderBag($bag1->allPreserveCase());
$this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
}

public function testToStringIncludesCookieHeaders()
{
$bag = new ResponseHeaderBag(array());
Expand All @@ -135,7 +143,7 @@ public function testClearCookieSecureNotHttpOnly()
public function testReplace()
{
$bag = new ResponseHeaderBag(array());
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));

$bag->replace(array('Cache-Control' => 'public'));
Expand All @@ -146,12 +154,12 @@ public function testReplace()
public function testReplaceWithRemove()
{
$bag = new ResponseHeaderBag(array());
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));

$bag->remove('Cache-Control');
$bag->replace(array());
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/ResponseTest.php
Expand Up @@ -33,7 +33,7 @@ public function testToString()
$response = new Response();
$response = explode("\r\n", $response);
$this->assertEquals('HTTP/1.0 200 OK', $response[0]);
$this->assertEquals('Cache-Control: no-cache', $response[1]);
$this->assertEquals('Cache-Control: no-cache, private', $response[1]);
}

public function testClone()
Expand Down

0 comments on commit 2954236

Please sign in to comment.