Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Client.php

function Client::configureDefaults

Configures the default options for a client.

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 229

Class

Client
@final

Namespace

GuzzleHttp

Code

private function configureDefaults(array $config) : void {
    $defaults = [
        'allow_redirects' => RedirectMiddleware::$defaultSettings,
        'http_errors' => true,
        'decode_content' => true,
        'verify' => true,
        'cookies' => false,
        'idn_conversion' => 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 === 'cli' && ($proxy = Utils::getenv('HTTP_PROXY'))) {
        $defaults['proxy']['http'] = $proxy;
    }
    if ($proxy = Utils::getenv('HTTPS_PROXY')) {
        $defaults['proxy']['https'] = $proxy;
    }
    if ($noProxy = Utils::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' => Utils::defaultUserAgent(),
        ];
    }
    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'] = Utils::defaultUserAgent();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal