Permalink
Browse files

Adding protocol() method to CakeResponse to be able to change it on t…

…he fly
  • Loading branch information...
1 parent 6211be2 commit 336ba1965ea22f701f568c93df6067abef5939f7 @lorenzo lorenzo committed Nov 4, 2011
Showing with 27 additions and 0 deletions.
  1. +13 −0 lib/Cake/Network/CakeResponse.php
  2. +14 −0 lib/Cake/Test/Case/Network/CakeResponseTest.php
@@ -683,6 +683,19 @@ public function download($filename) {
$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.
@@ -500,4 +500,18 @@ public function testSendContentLength() {
$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();
+ }
}

0 comments on commit 336ba19

Please sign in to comment.