summaryrefslogtreecommitdiff
path: root/inc/HTTPClient.php
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2012-02-22 17:34:53 +0100
committerAndreas Gohr <gohr@cosmocode.de>2012-02-22 17:36:24 +0100
commit361171a4e89a313fae8aa823c2279b32ec0c08bc (patch)
treeda9ba3ef7f68e08b194b79979c2cc16301c4453d /inc/HTTPClient.php
parenta699035c4f7aa040cc4170401b2f9c48966eba5b (diff)
downloadrpg-361171a4e89a313fae8aa823c2279b32ec0c08bc.tar.gz
rpg-361171a4e89a313fae8aa823c2279b32ec0c08bc.tar.bz2
simpler/more robust header parsing in HTTPClient
The previous regexp approach failed for empty headers.
Diffstat (limited to 'inc/HTTPClient.php')
-rw-r--r--inc/HTTPClient.php13
1 files changed, 7 insertions, 6 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 641950348..f0470e736 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -580,13 +580,14 @@ class HTTPClient {
*/
function _parseHeaders($string){
$headers = array();
- if (!preg_match_all('/^\s*([\w-]+)\s*:\s*([\S \t]+)\s*$/m', $string,
- $matches, PREG_SET_ORDER)) {
- return $headers;
- }
- foreach($matches as $match){
- list(, $key, $val) = $match;
+ $lines = explode("\n",$string);
+ array_shift($lines); //skip first line (status)
+ foreach($lines as $line){
+ list($key, $val) = explode(':',$line,2);
+ $key = trim($key);
+ $val = trim($val);
$key = strtolower($key);
+ if(!$key) continue;
if(isset($headers[$key])){
if(is_array($headers[$key])){
$headers[$key][] = $val;