closes #47
This commit is contained in:
Ahmad Nassri
2015-02-05 11:33:59 -05:00
parent 5fa02336f9
commit c5be546d1b
2 changed files with 48 additions and 1 deletions

View File

@@ -7,6 +7,10 @@ use Unirest\Response;
class Request
{
private static $proxyPort = false;
private static $proxyType = CURLPROXY_HTTP;
private static $proxyTunnel = false;
private static $proxyAddress = false;
private static $jsonOpts = array();
private static $verifyPeer = true;
private static $socketTimeout = null;
@@ -77,6 +81,22 @@ class Request
return self::$defaultHeaders = array();
}
/**
* Set proxy to use
*
* @param string $address proxy address
* @param string $port proxy port
* @param string $port proxy type (Available options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5_HOSTNAME)
* @param string $tunnel enable/disable tunneling
*/
public static function proxy($address, $port = 1080, $type = CURLPROXY_HTTP, $tunnel = false)
{
self::$proxyType = $type;
self::$proxyPort = $port;
self::$proxyTunnel = $tunnel;
self::$proxyAddress = $address;
}
/**
* Send a GET request to a URL
*
@@ -283,6 +303,13 @@ class Request
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . ((empty($password)) ? '' : $password));
}
if (self::$proxyAddress) {
curl_setopt($ch, CURLOPT_PROXYTYPE, self::$proxyType);
curl_setopt($ch, CURLOPT_PROXY, self::$proxyAddress);
curl_setopt($ch, CURLOPT_PROXYPORT, self::$proxyPort);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, self::$proxyTunnel);
}
$response = curl_exec($ch);
$error = curl_error($ch);