Merge pull request #259 from zachborboa/master

Fix #257
This commit is contained in:
Zach Borboa
2015-10-27 22:10:22 -07:00
2 changed files with 16 additions and 1 deletions
+3 -1
View File
@@ -544,7 +544,9 @@ class Curl
public function setCookie($key, $value)
{
$this->cookies[$key] = $value;
$this->setOpt(CURLOPT_COOKIE, str_replace(' ', '%20', urldecode(http_build_query($this->cookies, '', '; '))));
$this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) {
return $k . '=' . str_replace(' ', '%20', $v);
}, array_keys($this->cookies), array_values($this->cookies))));
}
/**
+13
View File
@@ -662,6 +662,19 @@ class CurlTest extends PHPUnit_Framework_TestCase
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
}
public function testMultipleCookies()
{
$curl = new Curl();
$curl->setCookie('cookie', 'Om nom nom nom');
$curl->setCookie('foo', 'bar');
$reflectionClass = new ReflectionClass('\Curl\Curl');
$reflectionProperty = $reflectionClass->getProperty('options');
$reflectionProperty->setAccessible(true);
$options = $reflectionProperty->getValue($curl);
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $options[CURLOPT_COOKIE]);
}
public function testCookieEncodingColon()
{
$curl = new Curl();