mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding CakeResponse::vary()
This commit is contained in:
parent
3240f6221e
commit
803d49c7c6
2 changed files with 42 additions and 0 deletions
|
@ -854,6 +854,27 @@ class CakeResponse {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Vary header for the response, if an array is passed,
|
||||
* values will be imploded into a comma separated string. If no
|
||||
* parameters are passed, then an array with the current Vary header
|
||||
* value is returned
|
||||
*
|
||||
* @param string|array $cacheVariances a single Vary string or a array
|
||||
* containig the list for variances.
|
||||
* @return array
|
||||
**/
|
||||
public function vary($cacheVariances = null) {
|
||||
if ($cacheVariances !== null) {
|
||||
$cacheVariances = (array) $cacheVariances;
|
||||
$this->_headers['Vary'] = implode(', ', $cacheVariances);
|
||||
}
|
||||
if (isset($this->_headers['Vary'])) {
|
||||
return explode(', ', $this->_headers['Vary']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DateTime object initialized at the $time param and using UTC
|
||||
* as timezone
|
||||
|
|
|
@ -763,4 +763,25 @@ class CakeResponseTest extends CakeTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getting/setting the Vary header
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testVary() {
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
||||
$response->vary('Accept-encoding');
|
||||
$this->assertEquals(array('Accept-encoding'), $response->vary());
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Vary', 'Accept-encoding');
|
||||
$response->send();
|
||||
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
||||
$response->vary(array('Accept-language', 'Accept-encoding'));
|
||||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Vary', 'Accept-language, Accept-encoding');
|
||||
$response->send();
|
||||
$this->assertEquals(array('Accept-language', 'Accept-encoding'), $response->vary());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue