mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'http-response-code' into master.
Merge changes from #3016 into master. Closes #3016
This commit is contained in:
commit
d559e429e6
2 changed files with 38 additions and 1 deletions
|
@ -159,7 +159,7 @@ class HttpSocketResponse implements ArrayAccess {
|
|||
$this->raw = $message;
|
||||
$this->body = (string)substr($message, strlen($match[0]));
|
||||
|
||||
if (preg_match("/(.+) ([0-9]{3}) (.+)\r\n/DU", $statusLine, $match)) {
|
||||
if (preg_match("/(.+) ([0-9]{3})\s*([^ ]*)\r\n/DU", $statusLine, $match)) {
|
||||
$this->httpVersion = $match[1];
|
||||
$this->code = $match[2];
|
||||
$this->reasonPhrase = $match[3];
|
||||
|
|
|
@ -1754,4 +1754,41 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->assertContains('Failed to enable crypto', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for status codes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test response status parsing
|
||||
*
|
||||
* @dataProvider statusProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testResponseStatusParsing($status, $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));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
|
||||
$response = $this->Socket->request('http://www.cakephp.org/');
|
||||
$this->assertInstanceOf('HttpSocketResponse', $response);
|
||||
$expected = array(
|
||||
'http-version' => 'HTTP/1.1',
|
||||
'code' => '200',
|
||||
'reason-phrase' => $msg
|
||||
);
|
||||
$this->assertEquals($expected, $response['status']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue