You are here

function _chr_get_proxy_variable in cURL HTTP Request 7

Get proxy settings for CHR.

Parameters

string $proxy: The name of proxy setting variable to retrieve.

Return value

The proxy setting variable to retrieve.

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

File

./chr.module, line 526
cURL HTTP Request methods

Code

function _chr_get_proxy_variable($proxy) {

  // Attempt to retrieve $proxy_var, which could either
  // be 'http_proxy' or 'https_proxy'.
  $proxy_var = variable_get($proxy);

  // If the requested $proxy_var hasn't been found,
  // let's try and work it out based on other variables.
  if (empty($proxy_var)) {
    switch ($proxy) {

      // Let's always assume to fall back on the HTTP proxy settings whenever
      // HTTPS proxy settings are not found.
      case 'https_proxy':

        // The first attempt is to see if the CHR-specific HTTP settings have
        // been set. If so, let's just use that to for 'https_proxy'.
        if ($proxy_var = variable_get('http_proxy')) {
          break;
        }

        // If 'http_proxy' wasn't set, let's fall through to the next case,
        // so that we try and fall back on Drupal standard proxy
        // settings for HTTP. Therefore, no 'break' required here.
      case 'http_proxy':

        // If a proxy server is set in Drupal, start building an 'http_proxy'
        // setting in the format expected by CHR.
        if ($proxy_server = variable_get('proxy_server')) {
          $proxy_var['server'] = $proxy_server;
          $proxy_var['port'] = variable_get('proxy_port', 8080);
          if ($proxy_username = variable_get('proxy_username')) {
            $proxy_var['username'] = $proxy_username;
          }
          if ($proxy_password = variable_get('proxy_password')) {
            $proxy_var['password'] = $proxy_password;
          }
          elseif (isset($proxy_var['username'])) {
            $proxy_var['password'] = '';
          }
          if ($proxy_exceptions = variable_get('proxy_exceptions')) {
            $proxy_var['exceptions'] = $proxy_exceptions;
          }
        }
        break;
    }
  }
  $drupal_proxy_server = variable_get('proxy_server');
  if (empty($proxy_var) and isset($drupal_proxy_server)) {
    $proxy_var = array(
      'server' => $drupal_proxy_server,
      'port' => variable_get('proxy_port'),
      'username' => variable_get('proxy_username'),
      'password' => variable_get('proxy_password'),
      'exceptions' => variable_get('proxy_exceptions'),
    );
    $proxy_var = array_filter($proxy_var);
  }

  // If a server wasn't set, $proxy_var remains NULL.
  // Either way, return $proxy_var.
  return $proxy_var;
}