Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow additional status codes through constructor
through $options['statusCodes']
  • Loading branch information
mouyang committed Jan 14, 2014
1 parent 05b2196 commit 84eb46d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Cake/Network/CakeResponse.php
Expand Up @@ -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
Expand All @@ -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']);
}
Expand Down
15 changes: 15 additions & 0 deletions lib/Cake/Test/Case/Network/CakeResponseTest.php
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 84eb46d

Please sign in to comment.