You are here

function _chr_curl_set_proxy_settings in cURL HTTP Request 6

Same name and namespace in other branches
  1. 7 chr.module \_chr_curl_set_proxy_settings()

Set proxy settings

Parameters

array $options [reference]: Options array

object $ch [reference]: cURL Object

array $uri [reference]: URI array

1 call to _chr_curl_set_proxy_settings()
chr_curl_http_request in ./chr.module
Performs an HTTP request.

File

./chr.module, line 354

Code

function _chr_curl_set_proxy_settings(&$options, &$ch, &$uri) {

  // Select the right proxy for the right protocol.
  $proxy = 'https' == $uri['scheme'] ? $options['https_proxy'] : $options['http_proxy'];

  // Nullify the proxy if the host to send the request to is part of the proxy's exceptions.
  if (!empty($proxy['exceptions']) && in_array($uri['host'], $proxy['exceptions'])) {
    $proxy = NULL;
  }
  if (!empty($proxy)) {
    curl_setopt($ch, CURLOPT_PROXY, $proxy['server']);
    curl_setopt($ch, CURLOPT_PROXYPORT, $proxy['port']);

    // For the time being let's just support HTTP proxies with basic authentication.
    if (isset($proxy['username']) && isset($proxy['password'])) {
      curl_setopt($ch, CURLOPT_PROXYUSERPWD, implode(':', array(
        $proxy['username'],
        $proxy['password'],
      )));
      curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
      curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
    }
  }
}