mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Merge pull request #300 from zachborboa/299
Fix #299: Add Curl::getResponseCookies()
This commit is contained in:
@@ -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())
|
||||
|
||||
+13
-2
@@ -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
|
||||
*
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user