diff --git a/Parsers/HTTPHeadersParser.php b/Parsers/HTTPHeadersParser.php index d05b51d..9201fc7 100644 --- a/Parsers/HTTPHeadersParser.php +++ b/Parsers/HTTPHeadersParser.php @@ -45,9 +45,19 @@ public static function parse($headers) { return strtoupper($matches[0]); }, strtolower(trim($match[1]))); - $carry[$match[1]] = isset($carry[$match[1]]) ? [$carry[$match[1]], $match[2]] : trim($match[2]); + if (!isset($carry[$match[1]])) { + $carry[$match[1]] = trim($match[2]); + return $carry; + } + + if (is_array($carry[$match[1]])) { + $carry[$match[1]][] = trim($match[2]); + return $carry; + } + + $carry[$match[1]] = [$carry[$match[1]], trim($match[2])]; return $carry; }, []); } -} \ No newline at end of file +} diff --git a/Tests/Functional/Parsers/HTTPHeadersParserTest.php b/Tests/Functional/Parsers/HTTPHeadersParserTest.php index f44af13..85fd71d 100644 --- a/Tests/Functional/Parsers/HTTPHeadersParserTest.php +++ b/Tests/Functional/Parsers/HTTPHeadersParserTest.php @@ -30,7 +30,7 @@ * * @SuppressWarnings("PHPMD.StaticAccess") */ -class ResponseHeadersTest extends \PHPUnit_Framework_TestCase { +class ResponseHeadersTest extends \PHPUnit_Framework_TestCase { /** * @test @@ -66,13 +66,14 @@ public function testParse() { */ public function testParseCookie() { $headers = "Set-Cookie: foo=bar\r\n". - "Set-Cookie: baz=quux\r\n"; + "Set-Cookie: baz=quux\r\n". + "Set-Cookie: quux=baz\r\n"; $returnValue = HTTPHeadersParser::parse($headers); $this->assertTrue(is_array($returnValue)); $this->assertTrue(isset($returnValue['Set-Cookie'])); $this->assertTrue(is_array($returnValue['Set-Cookie'])); - $this->assertEquals(count($returnValue['Set-Cookie']), 2); + $this->assertEquals(count($returnValue['Set-Cookie']), 3); } /**