Skip to content

Commit 93350fe

Browse files
committed
Fix php-curl-class#31: Combine multiple header fields into a comma-separated list
1 parent 9671814 commit 93350fe

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Curl.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ private function parseHeaders($raw_headers)
246246
list($key, $value) = explode(':', $raw_headers[$i], 2);
247247
$key = trim($key);
248248
$value = trim($value);
249-
if (array_key_exists($key, $http_headers)) {
249+
// Use isset() as array_key_exists() and ArrayAccess are not compatible.
250+
if (isset($http_headers[$key])) {
250251
$http_headers[$key] .= ',' . $value;
251252
} else {
252253
$http_headers[$key] = $value;

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ public function testCookieJar() {
277277
$this->assertFalse(file_exists($cookie_file));
278278
}
279279

280+
public function testMultipleCookieResponse() {
281+
$test = new Test();
282+
$test->server('multiple_cookie', 'GET');
283+
$this->assertEquals($test->curl->response_headers['Set-Cookie'], 'cookie1=scrumptious,cookie2=mouthwatering');
284+
}
285+
280286
public function testError() {
281287
$test = new Test();
282288
$test->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);

tests/PHPCurlClass/server.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
setcookie('mycookie', 'yum');
8181
exit;
8282
}
83+
else if ($test === 'multiple_cookie') {
84+
setcookie('cookie1', 'scrumptious');
85+
setcookie('cookie2', 'mouthwatering');
86+
exit;
87+
}
8388
else if ($test === 'response_header') {
8489
header('Content-Type: application/json');
8590
header('ETag: ' . md5('worldpeace'));

0 commit comments

Comments
 (0)