From 7c5d5a98676a23bc8070212b468185b5c3b7dfd5 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Tue, 29 Mar 2011 13:04:34 -0500 Subject: [PATCH] [Http] Cleaning up message parsing --- library/Guzzle/Http/Message/RequestFactory.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/Guzzle/Http/Message/RequestFactory.php b/library/Guzzle/Http/Message/RequestFactory.php index 697c9262..6adb6b5e 100644 --- a/library/Guzzle/Http/Message/RequestFactory.php +++ b/library/Guzzle/Http/Message/RequestFactory.php @@ -76,14 +76,17 @@ class RequestFactory $message = preg_replace("/([^\r])(\n)\b/", "$1\r\n", $message); $parts = explode("\r\n\r\n", $message, 2); $headers = array(); - $scheme = $host = $method = $user = $pass = $query = $port = ''; + $scheme = $host = $method = $user = $pass = $query = $port = $version = $protocol = ''; $path = '/'; // Parse each line in the message foreach (explode("\r\n", $parts[0]) as $line) { - if (preg_match('/^(GET|POST|PUT|HEAD|DELETE|TRACE|OPTIONS)\s+\/*.+\s+[A-Za-z]+\/[0-9]\.[0-9]\s*$/i', $line)) { - list($method, $path, $protocol) = array_map('trim', explode(' ', $line, 3)); - list($protocol, $version) = explode('/', $protocol); + $matches = array(); + if (preg_match('#^(?GET|POST|PUT|HEAD|DELETE|TRACE|OPTIONS)\s+(?/.*)\s+(?\w+)/(?\d\.\d)\s*$#i', $line, $matches)) { + $method = strtoupper($matches['method']); + $protocol = strtoupper($matches['protocol']); + $path = $matches['path']; + $version = $matches['version']; $scheme = 'http'; } else if (strpos($line, ':')) { list($key, $value) = explode(':', $line, 2); @@ -130,8 +133,8 @@ class RequestFactory } return array( - 'method' => strtoupper($method), - 'protocol' => strtoupper($protocol), + 'method' => $method, + 'protocol' => $protocol, 'protocol_version' => $version, 'parts' => array( 'scheme' => $scheme,