mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adjusting HttpResponse responses in array to be more compatible.
This commit is contained in:
parent
dfb76d67da
commit
f45027ecd8
2 changed files with 13 additions and 5 deletions
|
@ -125,9 +125,14 @@ class HttpResponse implements ArrayAccess {
|
||||||
switch ($offset) {
|
switch ($offset) {
|
||||||
case 'raw':
|
case 'raw':
|
||||||
$firstLineLength = strpos($this->raw, "\r\n") + 2;
|
$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(
|
return array(
|
||||||
'status-line' => $this->httpVersion . ' ' . $this->code . ' ' . $this->reasonPhrase,
|
'status-line' => $this->httpVersion . ' ' . $this->code . ' ' . $this->reasonPhrase . "\r\n",
|
||||||
'header' => substr($this->raw, $firstLineLength, strpos($this->raw, "\r\n\r\n") - $firstLineLength),
|
'header' => $header,
|
||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
'response' => $this->raw
|
'response' => $this->raw
|
||||||
);
|
);
|
||||||
|
|
|
@ -122,13 +122,13 @@ class HttpResponseTest extends CakeTestCase {
|
||||||
$this->HttpResponse->body = 'This is a test!';
|
$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!";
|
$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);
|
$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);
|
$this->assertEqual($this->HttpResponse['raw']['header'], $expected2);
|
||||||
$expected3 = 'This is a test!';
|
$expected3 = 'This is a test!';
|
||||||
$this->assertEqual($this->HttpResponse['raw']['body'], $expected3);
|
$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);
|
$this->assertEqual($this->HttpResponse['raw']['response'], $expected);
|
||||||
|
|
||||||
$expected = 'HTTP/1.1';
|
$expected = 'HTTP/1.1';
|
||||||
|
@ -152,6 +152,9 @@ class HttpResponseTest extends CakeTestCase {
|
||||||
'bar' => array('value' => 'foo')
|
'bar' => array('value' => 'foo')
|
||||||
);
|
);
|
||||||
$this->assertEqual($this->HttpResponse['cookies'], $expected);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue