diff --git a/README.md b/README.md index 85a129d..8f44d9e 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ Curl::get($url, $data = array()) Curl::getCookie($key) Curl::getOpt($option) Curl::getResponseCookie($key) +Curl::getResponseCookies() Curl::head($url, $data = array()) Curl::headerCallback($ch, $header) Curl::options($url, $data = array()) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 5e0c701..7ce2d56 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -445,8 +445,8 @@ class Curl */ public function headerCallback($ch, $header) { - if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) == 1) { - $this->responseCookies[$cookie[1]] = $cookie[2]; + if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) { + $this->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B"); } $this->rawResponseHeaders .= $header; return strlen($header); @@ -632,6 +632,17 @@ class Curl return isset($this->responseCookies[$key]) ? $this->responseCookies[$key] : null; } + /** + * Get response cookies. + * + * @access public + * @return array + */ + public function getResponseCookies() + { + return $this->responseCookies; + } + /** * Set Port * diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 137383c..9f705dc 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -753,6 +753,10 @@ class CurlTest extends PHPUnit_Framework_TestCase $test = new Test(); $test->server('multiple_cookie', 'GET'); $this->assertEquals('cookie1=scrumptious,cookie2=mouthwatering', $test->curl->responseHeaders['Set-Cookie']); + + $response_cookies = $test->curl->getResponseCookies(); + $this->assertEquals('scrumptious', $response_cookies['cookie1']); + $this->assertEquals('mouthwatering', $response_cookies['cookie2']); } public function testDefaultTimeout()