You are here

private function Client::configureDefaults in Lockr 7.3

Configures the default options for a client.

Parameters

array $config:

1 call to Client::configureDefaults()
Client::__construct in vendor/guzzlehttp/guzzle/src/Client.php
Clients accept an array of constructor parameters.

File

vendor/guzzlehttp/guzzle/src/Client.php, line 158

Class

Client
@method ResponseInterface get(string|UriInterface $uri, array $options = []) @method ResponseInterface head(string|UriInterface $uri, array $options = []) @method ResponseInterface put(string|UriInterface $uri, array $options = []) @method…

Namespace

GuzzleHttp

Code

private function configureDefaults(array $config) {
  $defaults = [
    'allow_redirects' => RedirectMiddleware::$defaultSettings,
    'http_errors' => true,
    'decode_content' => true,
    'verify' => true,
    'cookies' => false,
  ];

  // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
  // We can only trust the HTTP_PROXY environment variable in a CLI
  // process due to the fact that PHP has no reliable mechanism to
  // get environment variables that start with "HTTP_".
  if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
    $defaults['proxy']['http'] = getenv('HTTP_PROXY');
  }
  if ($proxy = getenv('HTTPS_PROXY')) {
    $defaults['proxy']['https'] = $proxy;
  }
  if ($noProxy = getenv('NO_PROXY')) {
    $cleanedNoProxy = str_replace(' ', '', $noProxy);
    $defaults['proxy']['no'] = explode(',', $cleanedNoProxy);
  }
  $this->config = $config + $defaults;
  if (!empty($config['cookies']) && $config['cookies'] === true) {
    $this->config['cookies'] = new CookieJar();
  }

  // Add the default user-agent header.
  if (!isset($this->config['headers'])) {
    $this->config['headers'] = [
      'User-Agent' => default_user_agent(),
    ];
  }
  else {

    // Add the User-Agent header if one was not already set.
    foreach (array_keys($this->config['headers']) as $name) {
      if (strtolower($name) === 'user-agent') {
        return;
      }
    }
    $this->config['headers']['User-Agent'] = default_user_agent();
  }
}