From 336ba1965ea22f701f568c93df6067abef5939f7 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 4 Nov 2011 14:34:49 -0430 Subject: [PATCH] Adding protocol() method to CakeResponse to be able to change it on the fly --- lib/Cake/Network/CakeResponse.php | 13 +++++++++++++ lib/Cake/Test/Case/Network/CakeResponseTest.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index be9ce5ae861..74113c63a42 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.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. diff --git a/lib/Cake/Test/Case/Network/CakeResponseTest.php b/lib/Cake/Test/Case/Network/CakeResponseTest.php index 33123dd620b..fc38218cfff 100644 --- a/lib/Cake/Test/Case/Network/CakeResponseTest.php +++ b/lib/Cake/Test/Case/Network/CakeResponseTest.php @@ -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(); + } }