Browse Source

Merge pull request #2654 from mouyang/2.5-responseCodes

allow additional status codes through constructor
José Lorenzo Rodríguez 12 years ago
parent
commit
8b5336ade1
2 changed files with 19 additions and 0 deletions
  1. 4 0
      lib/Cake/Network/CakeResponse.php
  2. 15 0
      lib/Cake/Test/Case/Network/CakeResponseTest.php

+ 4 - 0
lib/Cake/Network/CakeResponse.php

@@ -379,6 +379,7 @@ class CakeResponse {
  *
  * @param array $options list of parameters to setup the response. Possible values are:
  *	- body: the response text that should be sent to the client
+ *	- statusCodes: additional allowable response codes
  *	- status: the HTTP status code to respond with
  *	- type: a complete mime-type string or an extension mapped in this class
  *	- charset: the charset for the response body
@@ -387,6 +388,9 @@ class CakeResponse {
 		if (isset($options['body'])) {
 			$this->body($options['body']);
 		}
+		if (isset($options['statusCodes'])) {
+			$this->httpCodes($options['statusCodes']);
+		}
 		if (isset($options['status'])) {
 			$this->statusCode($options['status']);
 		}

+ 15 - 0
lib/Cake/Test/Case/Network/CakeResponseTest.php

@@ -66,6 +66,21 @@ class CakeResponseTest extends CakeTestCase {
 		$this->assertEquals('my-custom-charset', $response->charset());
 		$this->assertEquals('audio/mpeg', $response->type());
 		$this->assertEquals(203, $response->statusCode());
+
+		$options = array(
+			'body' => 'This is the body',
+			'charset' => 'my-custom-charset',
+			'type' => 'mp3',
+			'status' => '422',
+			'statusCodes' => array(
+				422 => 'Unprocessable Entity'
+			)
+		);
+		$response = new CakeResponse($options);
+		$this->assertEquals($options['body'], $response->body());
+		$this->assertEquals($options['charset'], $response->charset());
+		$this->assertEquals($response->getMimeType($options['type']), $response->type());
+		$this->assertEquals($options['status'], $response->statusCode());
 	}
 
 /**