Skip to content
Permalink
Browse files

Capture the version when parsing response headers.

  • Loading branch information...
markstory committed Dec 28, 2012
1 parent 34a1106 commit f53e5b3872a12208d68293fa8e1aab4b73aba148
Showing with 5 additions and 3 deletions.
  1. +3 −2 lib/Cake/Network/Http/Response.php
  2. +2 −1 lib/Cake/Test/TestCase/Network/Http/ResponseTest.php
@@ -109,8 +109,9 @@ public function __construct($headers = [], $body = '') {
protected function _parseHeaders($headers) {
foreach ($headers as $key => $value) {
if (substr($value, 0, 5) === 'HTTP/') {
preg_match('/HTTP\/[\d.]+ ([0-9]+)/i', $value, $matches);
$this->_code = $matches[1];
preg_match('/HTTP\/([\d.]+) ([0-9]+)/i', $value, $matches);
$this->_version = $matches[1];
$this->_code = $matches[2];
continue;
}
list($name, $value) = explode(':', $value, 2);
@@ -23,12 +23,13 @@ class ResponseTest extends TestCase {
public function testHeaderParsing() {
$headers = [
'HTTP/1.1 200 OK',
'HTTP/1.0 200 OK',
'Content-Type : text/html;charset="UTF-8"',
'date: Tue, 25 Dec 2012 04:43:47 GMT',
];
$response = new Response($headers, 'ok');
$this->assertEquals('1.0', $response->version());
$this->assertEquals(200, $response->statusCode());
$this->assertEquals(
'text/html;charset="UTF-8"',

0 comments on commit f53e5b3

Please sign in to comment.
You can’t perform that action at this time.