diff --git a/cake/libs/http_response.php b/cake/libs/http_response.php index ef54423ab72..f0cc637c8c1 100644 --- a/cake/libs/http_response.php +++ b/cake/libs/http_response.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 ); diff --git a/cake/tests/cases/libs/http_response.test.php b/cake/tests/cases/libs/http_response.test.php index debac0735e5..6c3967a8953 100644 --- a/cake/tests/cases/libs/http_response.test.php +++ b/cake/tests/cases/libs/http_response.test.php @@ -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); } } \ No newline at end of file