Skip to content
Permalink
Browse files

Add withSharedMaxAge()

  • Loading branch information...
markstory committed Dec 5, 2016
1 parent 4f75c34 commit 986efd077121c04b0bf335fad50b264d395f5f6c
Showing with 35 additions and 0 deletions.
  1. +18 −0 src/Network/Response.php
  2. +17 −0 tests/TestCase/Network/ResponseTest.php
@@ -1331,6 +1331,24 @@ public function sharedMaxAge($seconds = null)
return null;
}
/**
* Create a new instance with the Cache-Control s-maxage directive.
*
* The max-age is the number of seconds after which the response should no longer be considered
* a good candidate to be fetched from a shared cache (like in a proxy server).
*
* @param int $seconds The number of seconds for shared max-age
* @return static
*/
public function withSharedMaxAge($seconds)
{
$new = clone $this;
$new->_cacheDirectives['s-maxage'] = $seconds;
$new->_setCacheControl();
return $new;
}
/**
* Sets the Cache-Control max-age directive.
* The max-age is the number of seconds after which the response should no longer be considered
@@ -980,6 +980,23 @@ public function testSharedMaxAge()
$this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
}
/**
* Tests setting of s-maxage Cache-Control directive
*
* @return void
*/
public function testWithSharedMaxAge()
{
$response = new Response();
$new = $response->withSharedMaxAge(3600);
$this->assertFalse($response->hasHeader('Cache-Control'));
$this->assertEquals('s-maxage=3600', $new->getHeaderLine('Cache-Control'));
$new = $response->withSharedMaxAge(3600)->withSharable(true);
$this->assertEquals('s-maxage=3600, public', $new->getHeaderLine('Cache-Control'));
}
/**
* Tests setting of must-revalidate Cache-Control directive
*

0 comments on commit 986efd0

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