Skip to content
Snippets Groups Projects
Commit 361171a4 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

simpler/more robust header parsing in HTTPClient

The previous regexp approach failed for empty headers.
parent a699035c
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment