Skip to content

Issues with HTTPHeadersParser #48

@tbyte80

Description

@tbyte80

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions