Skip to content

Commit

Permalink
Merge pull request #1072 from uzyn/httpresponse-3531
Browse files Browse the repository at this point in the history
Add OK or Successful HTTP codes 200-206 to HttpResponse::isOK().

Fixes #3531
  • Loading branch information
markstory committed Jan 15, 2013
2 parents 6e4d522 + bcdbdc8 commit a1035f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Network/Http/HttpResponse.php
Expand Up @@ -116,12 +116,12 @@ public function getHeader($name, $headers = null) {
}

/**
* If return is 200 (OK)
* If return is a valid 2xx (OK or Successful)
*
* @return boolean
*/
public function isOk() {
return $this->code == 200;
return in_array($this->code, array(200, 201, 202, 203, 204, 205, 206));
}

/**
Expand Down
28 changes: 26 additions & 2 deletions lib/Cake/Test/Case/Network/Http/HttpResponseTest.php
Expand Up @@ -157,12 +157,36 @@ public function testIsOk() {
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = -1;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 201;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 'what?';
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 200;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 201;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 202;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 203;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 204;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 205;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 206;
$this->assertTrue($this->HttpResponse->isOk());
$this->HttpResponse->code = 207;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 208;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 209;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 210;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 226;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 288;
$this->assertFalse($this->HttpResponse->isOk());
$this->HttpResponse->code = 301;
$this->assertFalse($this->HttpResponse->isOk());
}

/**
Expand Down

0 comments on commit a1035f7

Please sign in to comment.