Skip to content

Commit

Permalink
Adjusting HttpResponse responses in array to be more compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Dec 14, 2010
1 parent dfb76d6 commit f45027e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cake/libs/http_response.php
Expand Up @@ -125,9 +125,14 @@ public function offsetGet($offset) {
switch ($offset) {
case 'raw':
$firstLineLength = strpos($this->raw, "\r\n") + 2;
if ($this->raw[$firstLineLength] === "\r") {
$header = null;
} else {
$header = substr($this->raw, $firstLineLength, strpos($this->raw, "\r\n\r\n") - $firstLineLength) . "\r\n";
}
return array(
'status-line' => $this->httpVersion . ' ' . $this->code . ' ' . $this->reasonPhrase,
'header' => substr($this->raw, $firstLineLength, strpos($this->raw, "\r\n\r\n") - $firstLineLength),
'status-line' => $this->httpVersion . ' ' . $this->code . ' ' . $this->reasonPhrase . "\r\n",
'header' => $header,
'body' => $this->body,
'response' => $this->raw
);
Expand Down
9 changes: 6 additions & 3 deletions cake/tests/cases/libs/http_response.test.php
Expand Up @@ -122,13 +122,13 @@ public function testArrayAccess() {
$this->HttpResponse->body = 'This is a test!';
$this->HttpResponse->raw = "HTTP/1.1 200 OK\r\nServer: CakePHP\r\nContEnt-Type: text/plain\r\n\r\nThis is a test!";

$expected1 = 'HTTP/1.1 200 OK';
$expected1 = "HTTP/1.1 200 OK\r\n";
$this->assertEqual($this->HttpResponse['raw']['status-line'], $expected1);
$expected2 = "Server: CakePHP\r\nContEnt-Type: text/plain";
$expected2 = "Server: CakePHP\r\nContEnt-Type: text/plain\r\n";
$this->assertEqual($this->HttpResponse['raw']['header'], $expected2);
$expected3 = 'This is a test!';
$this->assertEqual($this->HttpResponse['raw']['body'], $expected3);
$expected = $expected1 . "\r\n" . $expected2 . "\r\n\r\n" . $expected3;
$expected = $expected1 . $expected2 . "\r\n" . $expected3;
$this->assertEqual($this->HttpResponse['raw']['response'], $expected);

$expected = 'HTTP/1.1';
Expand All @@ -152,6 +152,9 @@ public function testArrayAccess() {
'bar' => array('value' => 'foo')
);
$this->assertEqual($this->HttpResponse['cookies'], $expected);

$this->HttpResponse->raw = "HTTP/1.1 200 OK\r\n\r\nThis is a test!";
$this->assertIdentical($this->HttpResponse['raw']['header'], null);
}

}

0 comments on commit f45027e

Please sign in to comment.