mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fix incorrect status line parsing in HttpSocketResponse.
Allow for multi-word status reasons. Closes #3545
This commit is contained in:
parent
b1fe9134c6
commit
270e8774e4
2 changed files with 12 additions and 8 deletions
|
@ -159,10 +159,12 @@ class HttpSocketResponse implements ArrayAccess {
|
|||
$this->raw = $message;
|
||||
$this->body = (string)substr($message, strlen($match[0]));
|
||||
|
||||
if (preg_match("/(.+) ([0-9]{3})\s*([^ ]*)\r\n/DU", $statusLine, $match)) {
|
||||
if (preg_match("/(.+) ([0-9]{3})(?:\s+(\w.+))?\s*\r\n/DU", $statusLine, $match)) {
|
||||
$this->httpVersion = $match[1];
|
||||
$this->code = $match[2];
|
||||
$this->reasonPhrase = $match[3];
|
||||
if (isset($match[3])) {
|
||||
$this->reasonPhrase = $match[3];
|
||||
}
|
||||
}
|
||||
|
||||
$this->headers = $this->_parseHeader($header);
|
||||
|
|
|
@ -1762,10 +1762,12 @@ class HttpSocketTest extends CakeTestCase {
|
|||
*/
|
||||
public function statusProvider() {
|
||||
return array(
|
||||
array('HTTP/1.1 200 '),
|
||||
array('HTTP/1.1 200 '),
|
||||
array('HTTP/1.1 200'),
|
||||
array('HTTP/1.1 200 OK', 'OK'),
|
||||
array('HTTP/1.1 200 ', '200'),
|
||||
array('HTTP/1.1 200 ', '200'),
|
||||
array('HTTP/1.1 200', '200'),
|
||||
array('HTTP/1.1 200 OK', '200', 'OK'),
|
||||
array('HTTP/1.1 404 Not Found', '404', 'Not Found'),
|
||||
array('HTTP/1.1 404 Not Found', '404', 'Not Found'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1775,7 +1777,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @dataProvider statusProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testResponseStatusParsing($status, $msg = '') {
|
||||
public function testResponseStatusParsing($status, $code, $msg = '') {
|
||||
$this->Socket->connected = true;
|
||||
$serverResponse = $status . "\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n\r\n<h1>This is a test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
|
@ -1785,7 +1787,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->assertInstanceOf('HttpSocketResponse', $response);
|
||||
$expected = array(
|
||||
'http-version' => 'HTTP/1.1',
|
||||
'code' => '200',
|
||||
'code' => $code,
|
||||
'reason-phrase' => $msg
|
||||
);
|
||||
$this->assertEquals($expected, $response['status']);
|
||||
|
|
Loading…
Add table
Reference in a new issue