CircleOfNice / CiRestClientBundle

Mapper for PHP internal curl library
GNU General Public License v3.0
57 stars 20 forks source link

Issues with HTTPHeadersParser #48

Open tbyte80 opened 6 years ago

tbyte80 commented 6 years ago

Hello,

the method HTTPHeadersParser::parse is not producing a valid headers array in some situations. If the response contains multiple headers with the same name (which happenend to me with "set-cookie") an awkward nested array is created in this line:

$carry[$match[1]] = isset($carry[$match[1]]) ? [$carry[$match[1]], $match[2]] : trim($match[2]);

So if you have more than two "set-cookie" headers you would end up with a multiple nested array which cannot be handled by symfonys Cookie::fromString($cookie) method (explode will fail and cause exception).

I fixed it by writing my own global "http_parse_headers" function, replacing the line above with this:

if( isset($carry[$match[1]]) ) {
    if(!is_array($carry[$match[1]]))
        $carry[$match[1]] = array($carry[$match[1]], $match[2]);
     else{
         $carry[$match[1]][] = trim($match[2]);
     }
} else {
    $carry[$match[1]] = trim($match[2]);
}

Greetings!