@@ -37,6 +37,7 @@ class Curl
37
37
private $ completeFunction = null ;
38
38
39
39
private $ cookies = array ();
40
+ private $ responseCookies = array ();
40
41
private $ headers = array ();
41
42
private $ options = array ();
42
43
@@ -297,14 +298,14 @@ public function error($callback)
297
298
*/
298
299
public function exec ($ ch = null )
299
300
{
301
+ $ this ->responseCookies = array ();
300
302
if (!($ ch === null )) {
301
303
$ this ->rawResponse = curl_multi_getcontent ($ ch );
302
304
} else {
303
305
$ this ->call ($ this ->beforeSendFunction );
304
306
$ this ->rawResponse = curl_exec ($ this ->curl );
305
307
$ this ->curlErrorCode = curl_errno ($ this ->curl );
306
308
}
307
-
308
309
$ this ->curlErrorMessage = curl_error ($ this ->curl );
309
310
$ this ->curlError = !($ this ->curlErrorCode === 0 );
310
311
$ this ->httpStatusCode = curl_getinfo ($ this ->curl , CURLINFO_HTTP_CODE );
@@ -401,6 +402,9 @@ public function head($url, $data = array())
401
402
*/
402
403
public function headerCallback ($ ch , $ header )
403
404
{
405
+ if (preg_match ('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi ' , $ header , $ cookie ) == 1 ) {
406
+ $ this ->responseCookies [$ cookie [1 ]] = $ cookie [2 ];
407
+ }
404
408
$ this ->rawResponseHeaders .= $ header ;
405
409
return strlen ($ header );
406
410
}
@@ -539,6 +543,16 @@ public function setCookie($key, $value)
539
543
$ this ->setOpt (CURLOPT_COOKIE , str_replace (' ' , '%20 ' , urldecode (http_build_query ($ this ->cookies , '' , '; ' ))));
540
544
}
541
545
546
+ /**
547
+ * get Cookie of Response, if Key is set. Otherwise return NULL
548
+ *
549
+ * @access public
550
+ * @param $key
551
+ */
552
+ public function getResponseCookie ($ key ) {
553
+ return (isset ($ this ->responseCookies [$ key ]))?$ this ->responseCookies [$ key ]:NULL ;
554
+ }
555
+
542
556
/**
543
557
* Set Port
544
558
*
0 commit comments