Skip to content
Permalink
Browse files

Adjusting HttpResponse responses in array to be more compatible.

  • Loading branch information...
jrbasso committed Dec 14, 2010
1 parent dfb76d6 commit f45027ecd87041be3a8f257664b661650a315bd7
Showing with 13 additions and 5 deletions.
  1. +7 −2 cake/libs/http_response.php
  2. +6 −3 cake/tests/cases/libs/http_response.test.php
@@ -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
);
@@ -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';
@@ -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.
You can’t perform that action at this time.