diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index 8be475c01..b20e0643b 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/lib/Cake/Network/Http/HttpSocketResponse.php @@ -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]; diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index c2fcd1a22..8f3c46079 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -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

This is a test!

"; + $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']); + } + }