Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with HTTPHeadersParser #48

Open
tbyte80 opened this issue Jan 3, 2018 · 0 comments
Open

Issues with HTTPHeadersParser #48

tbyte80 opened this issue Jan 3, 2018 · 0 comments

Comments

@tbyte80
Copy link

tbyte80 commented Jan 3, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant