Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow additional status codes through constructor

through $options['statusCodes']
  • Loading branch information...
commit 84eb46dbdc2f1f77d521f026062da3df0b04813b 1 parent 05b2196
@mouyang mouyang authored
View
4 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
+ * - codes: 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 @@ public function __construct(array $options = array()) {
if (isset($options['body'])) {
$this->body($options['body']);
}
+ if (isset($options['statusCodes'])) {
+ $this->httpCodes($options['statusCodes']);
+ }
if (isset($options['status'])) {
$this->statusCode($options['status']);
}
View
15 lib/Cake/Test/Case/Network/CakeResponseTest.php
@@ -66,6 +66,21 @@ public function testConstruct() {
$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());
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.