From 561bf6e32f185aab2f4db82e1e45446a65f0c068 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Fri, 5 Feb 2016 02:51:54 -0800 Subject: [PATCH 1/3] Add Curl::getResponseCookies() --- src/Curl/Curl.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 5e0c701..5c20492 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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 * From 6214b87670a9164bb787ddfa7826b14a70899da6 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Fri, 5 Feb 2016 02:52:22 -0800 Subject: [PATCH 2/3] Add test for Curl::getResponseCookies() --- src/Curl/Curl.php | 4 ++-- tests/PHPCurlClass/PHPCurlClassTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 5c20492..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); 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() From c9f785eff5353fdb3fcf3586d8757e7254f9217e Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Fri, 5 Feb 2016 03:02:26 -0800 Subject: [PATCH 3/3] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) 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())