Skip to content

Commit

Permalink
Merge pull request #11521 from gotoeveryone/features/client-204
Browse files Browse the repository at this point in the history
Add to `203` and `204` allowed status code at `Cake\Http\Client\Response::isOk()`
  • Loading branch information
markstory committed Dec 9, 2017
2 parents 829778d + 9dbdfd5 commit 3692f76
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Http/Client/Message.php
Expand Up @@ -45,6 +45,20 @@ class Message
*/
const STATUS_ACCEPTED = 202;

/**
* HTTP 203 code
*
* @var int
*/
const STATUS_NON_AUTHORITATIVE_INFORMATION = 203;

/**
* HTTP 204 code
*
* @var int
*/
const STATUS_NO_CONTENT = 204;

/**
* HTTP 301 code
*
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Client/Response.php
Expand Up @@ -236,7 +236,9 @@ public function isOk()
$codes = [
static::STATUS_OK,
static::STATUS_CREATED,
static::STATUS_ACCEPTED
static::STATUS_ACCEPTED,
static::STATUS_NON_AUTHORITATIVE_INFORMATION,
static::STATUS_NO_CONTENT
];

return in_array($this->code, $codes);
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Http/Client/ResponseTest.php
Expand Up @@ -215,6 +215,20 @@ public function testIsOk()
$response = new Response($headers, 'ok');
$this->assertTrue($response->isOk());

$headers = [
'HTTP/1.1 203 Non-Authoritative Information',
'Content-Type: text/html'
];
$response = new Response($headers, 'ok');
$this->assertTrue($response->isOk());

$headers = [
'HTTP/1.1 204 No Content',
'Content-Type: text/html'
];
$response = new Response($headers, 'ok');
$this->assertTrue($response->isOk());

$headers = [
'HTTP/1.1 301 Moved Permanently',
'Content-Type: text/html'
Expand Down

0 comments on commit 3692f76

Please sign in to comment.