From 93350fe3a9e33cc79d4db5ab38a36674f398f468 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 29 Mar 2014 02:24:04 -0700 Subject: [PATCH] Fix #31: Combine multiple header fields into a comma-separated list --- src/Curl.class.php | 3 ++- tests/PHPCurlClass/PHPCurlClassTest.php | 6 ++++++ tests/PHPCurlClass/server.php | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Curl.class.php b/src/Curl.class.php index 2311a8d..d3d06d3 100644 --- a/src/Curl.class.php +++ b/src/Curl.class.php @@ -246,7 +246,8 @@ class Curl list($key, $value) = explode(':', $raw_headers[$i], 2); $key = trim($key); $value = trim($value); - if (array_key_exists($key, $http_headers)) { + // Use isset() as array_key_exists() and ArrayAccess are not compatible. + if (isset($http_headers[$key])) { $http_headers[$key] .= ',' . $value; } else { $http_headers[$key] = $value; diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 5b8823f..1280caf 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -277,6 +277,12 @@ class CurlTest extends PHPUnit_Framework_TestCase { $this->assertFalse(file_exists($cookie_file)); } + public function testMultipleCookieResponse() { + $test = new Test(); + $test->server('multiple_cookie', 'GET'); + $this->assertEquals($test->curl->response_headers['Set-Cookie'], 'cookie1=scrumptious,cookie2=mouthwatering'); + } + public function testError() { $test = new Test(); $test->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000); diff --git a/tests/PHPCurlClass/server.php b/tests/PHPCurlClass/server.php index 9090f3d..96e835b 100644 --- a/tests/PHPCurlClass/server.php +++ b/tests/PHPCurlClass/server.php @@ -80,6 +80,11 @@ else if ($test === 'cookiejar') { setcookie('mycookie', 'yum'); exit; } +else if ($test === 'multiple_cookie') { + setcookie('cookie1', 'scrumptious'); + setcookie('cookie2', 'mouthwatering'); + exit; +} else if ($test === 'response_header') { header('Content-Type: application/json'); header('ETag: ' . md5('worldpeace'));