Adding protocol() method to CakeResponse to be able to change it on the fly

This commit is contained in:
Jose Lorenzo Rodriguez 2011-11-04 14:34:49 -04:30
parent 6211be2acc
commit 336ba1965e
2 changed files with 27 additions and 0 deletions

View file

@ -683,6 +683,19 @@ class CakeResponse {
$this->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
}
/**
* Sets the protocol to be used when sending the response. Defaults to HTTP/1.1
* If called with no arguments, it will return the current configured protocol
*
* @return string protocol to be used for sending response
*/
public function protocol($protocol = null) {
if ($protocol !== null) {
$this->_protocol = $protocol;
}
return $this->_protocol;
}
/**
* String conversion. Fetches the response body as a string.
* Does *not* send headers.

View file

@ -500,4 +500,18 @@ class CakeResponseTest extends CakeTestCase {
$response->send();
ob_end_clean();
}
/**
* Tests getting/setting the protocol
*
* @return void
*/
public function testProtocol() {
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
$response->protocol('HTTP/1.0');
$this->assertEquals('HTTP/1.0', $response->protocol());
$response->expects($this->at(0))
->method('_sendHeader')->with('HTTP/1.0 200 OK');
$response->send();
}
}