Upstream patch: Remote updates to support sessions
This commit is contained in:
parent
ad5b674d22
commit
174b78800c
@ -9,6 +9,8 @@
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
class Kohana_Remote {
|
||||
// Store our curl session resource
|
||||
static $remote = NULL;
|
||||
|
||||
// Default curl options
|
||||
public static $default_options = array
|
||||
@ -36,7 +38,7 @@ class Kohana_Remote {
|
||||
* @return string
|
||||
* @throws Kohana_Exception
|
||||
*/
|
||||
public static function get($url, array $options = NULL)
|
||||
public static function get($url, array $options = NULL, $session = FALSE)
|
||||
{
|
||||
if ($options === NULL)
|
||||
{
|
||||
@ -52,8 +54,20 @@ class Kohana_Remote {
|
||||
// The transfer must always be returned
|
||||
$options[CURLOPT_RETURNTRANSFER] = TRUE;
|
||||
|
||||
// If we have an old session, lets auto close it.
|
||||
if (! $session AND Remote::$remote)
|
||||
Remote::clear();
|
||||
|
||||
// Open a new remote connection
|
||||
$remote = curl_init($url);
|
||||
if (! $session OR is_null(Remote::$remote))
|
||||
{
|
||||
$remote = Remote::$remote = curl_init($url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$remote = Remote::$remote;
|
||||
curl_setopt($remote,CURLOPT_URL,$url);
|
||||
}
|
||||
|
||||
// Set connection options
|
||||
if ( ! curl_setopt_array($remote, $options))
|
||||
@ -77,9 +91,6 @@ class Kohana_Remote {
|
||||
$error = curl_error($remote);
|
||||
}
|
||||
|
||||
// Close the connection
|
||||
curl_close($remote);
|
||||
|
||||
if (isset($error))
|
||||
{
|
||||
throw new Kohana_Exception('Error fetching remote :url [ status :code ] :error',
|
||||
@ -89,6 +100,17 @@ class Kohana_Remote {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an existing curl session
|
||||
*/
|
||||
public static function clear()
|
||||
{
|
||||
if (is_resource(Remote::$remote))
|
||||
curl_close(Remote::$remote);
|
||||
|
||||
Remote::$remote = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code (200, 500, etc) for a URL.
|
||||
*
|
||||
|
Reference in New Issue
Block a user