Skip to content

Commit 84eb46d

Browse files
committed
allow additional status codes through constructor
through $options['statusCodes']
1 parent 05b2196 commit 84eb46d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Cake/Network/CakeResponse.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ class CakeResponse {
379379
*
380380
* @param array $options list of parameters to setup the response. Possible values are:
381381
* - body: the response text that should be sent to the client
382+
* - codes: additional allowable response codes
382383
* - status: the HTTP status code to respond with
383384
* - type: a complete mime-type string or an extension mapped in this class
384385
* - charset: the charset for the response body
@@ -387,6 +388,9 @@ public function __construct(array $options = array()) {
387388
if (isset($options['body'])) {
388389
$this->body($options['body']);
389390
}
391+
if (isset($options['statusCodes'])) {
392+
$this->httpCodes($options['statusCodes']);
393+
}
390394
if (isset($options['status'])) {
391395
$this->statusCode($options['status']);
392396
}

lib/Cake/Test/Case/Network/CakeResponseTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ public function testConstruct() {
6666
$this->assertEquals('my-custom-charset', $response->charset());
6767
$this->assertEquals('audio/mpeg', $response->type());
6868
$this->assertEquals(203, $response->statusCode());
69+
70+
$options = array(
71+
'body' => 'This is the body',
72+
'charset' => 'my-custom-charset',
73+
'type' => 'mp3',
74+
'status' => '422',
75+
'statusCodes' => array(
76+
422 => 'Unprocessable Entity'
77+
)
78+
);
79+
$response = new CakeResponse($options);
80+
$this->assertEquals($options['body'], $response->body());
81+
$this->assertEquals($options['charset'], $response->charset());
82+
$this->assertEquals($response->getMimeType($options['type']), $response->type());
83+
$this->assertEquals($options['status'], $response->statusCode());
6984
}
7085

7186
/**

0 commit comments

Comments
 (0)