Skip to content
Permalink
Browse files

Add withDisabledCache() header macro.

  • Loading branch information...
markstory committed Nov 26, 2016
1 parent f4d7d35 commit 5326287d60500757e99d474a8d4928186dc235fd
Showing with 33 additions and 0 deletions.
  1. +13 −0 src/Network/Response.php
  2. +20 −0 tests/TestCase/Network/ResponseTest.php
@@ -1166,6 +1166,7 @@ public function charset($charset = null)
* Sets the correct headers to instruct the client to not cache the response
*
* @return void
* @deprected 3.4.0 Use withDisabledCache() instead.
*/
public function disableCache()
{
@@ -1174,6 +1175,18 @@ public function disableCache()
$this->_setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
}
/**
* Create a new instance with headers to instruct the client to not cache the response
*
* @return static
*/
public function withDisabledCache()
{
return $this->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')
->withHeader('Last-Modified', gmdate("D, d M Y H:i:s") . " GMT")
->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
}
/**
* Sets the correct headers to instruct the client to cache the response.
*
@@ -471,6 +471,26 @@ public function testDisableCache()
$this->assertEquals($expected, $response->header());
}
/**
* Tests the withDisabledCache method
*
* @return void
*/
public function testWithDisabledCache()
{
$response = new Response();
$expected = [
'Expires' => ['Mon, 26 Jul 1997 05:00:00 GMT'],
'Last-Modified' => [gmdate("D, d M Y H:i:s") . " GMT"],
'Cache-Control' => ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0'],
'Content-Type' => ['text/html; charset=UTF-8'],
];
$new = $response->withDisabledCache();
$this->assertFalse($response->hasHeader('Expires'), 'Old instance not mutated.');
$this->assertEquals($expected, $new->getHeaders());
}
/**
* Tests the cache method
*

0 comments on commit 5326287

Please sign in to comment.
You can’t perform that action at this time.