mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Implementing CakeResponse::notModified()
This commit is contained in:
parent
dbd097debb
commit
8e979cc83e
2 changed files with 43 additions and 1 deletions
|
@ -854,6 +854,30 @@ class CakeResponse {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response as Not Modified by removing any body contents
|
||||
* setting the status code to "304 Not Modified" and removing all
|
||||
* conflicting headers
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
public function notModified() {
|
||||
$this->statusCode(304);
|
||||
$this->body('');
|
||||
$remove = array(
|
||||
'Allow',
|
||||
'Content-Encoding',
|
||||
'Content-Language',
|
||||
'Content-Length',
|
||||
'Content-MD5',
|
||||
'Content-Type',
|
||||
'Last-Modified'
|
||||
);
|
||||
foreach ($remove as $header) {
|
||||
unset($this->_headers[$header]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Vary header for the response, if an array is passed,
|
||||
* values will be imploded into a comma separated string. If no
|
||||
|
|
|
@ -803,6 +803,24 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$response->expects($this->at(1))
|
||||
->method('_sendHeader')->with('Etag', 'W/"something"');
|
||||
$response->send();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the response is able to be marked as not modified
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNotModified() {
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
|
||||
$response->body('something');
|
||||
$response->statusCode(200);
|
||||
$response->length(100);
|
||||
$response->modified('now');
|
||||
$response->notModified();
|
||||
|
||||
$this->assertEmpty($response->header());
|
||||
$this->assertEmpty($response->body());
|
||||
$this->assertEquals(304, $response->statusCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue