From 217b436124259d1d68ab3e204bf725948ee64cb8 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Thu, 2 Apr 2015 14:11:23 -0400 Subject: [PATCH] manually applying PR by @daydiff due to complex merge issues, closes #67 --- src/Unirest/Request.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Unirest/Request.php b/src/Unirest/Request.php index e7e7661..263549e 100644 --- a/src/Unirest/Request.php +++ b/src/Unirest/Request.php @@ -7,11 +7,12 @@ use Unirest\Response; class Request { + private static $cookieFile = null; + private static $defaultHeaders = array(); private static $handle = null; private static $jsonOpts = array(); - private static $verifyPeer = true; private static $socketTimeout = null; - private static $defaultHeaders = array(); + private static $verifyPeer = true; private static $auth = array ( 'user' => '', @@ -102,6 +103,18 @@ class Request return self::defaultHeader('X-Mashape-Key', $key); } + /** + * Set a coockie file path for enabling coockie handling + * + * $cookieFile must be a correct path with permission to write to them + * + * @param string $cookieFile - path to file for saving coockie + */ + public static function cookieFile($cookieFile) + { + self::$cookieFile = $cookieFile; + } + /** * Clear all the default headers */ @@ -360,6 +373,11 @@ class Request curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout); } + if (self::$cookieFile) { + curl_setopt($ch, CURLOPT_COOKIEFILE, self::$cookieFile); + curl_setopt($ch, CURLOPT_COOKIEJAR, self::$cookieFile); + } + // supporting deprecated http auth method if (!empty($username)) { curl_setopt_array(self::$handle, array(