You are here

public function ClientFactory::fromOptions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Http/ClientFactory.php \Drupal\Core\Http\ClientFactory::fromOptions()

Constructs a new client object from some configuration.

Parameters

array $config: The config for the client.

Return value

\GuzzleHttp\Client The HTTP client.

File

core/lib/Drupal/Core/Http/ClientFactory.php, line 46
Contains \Drupal\Core\Http\ClientFactory.

Class

ClientFactory
Helper class to construct a HTTP client with Drupal specific config.

Namespace

Drupal\Core\Http

Code

public function fromOptions(array $config = []) {
  $default_config = [
    // Security consideration: we must not use the certificate authority
    // file shipped with Guzzle because it can easily get outdated if a
    // certificate authority is hacked. Instead, we rely on the certificate
    // authority file provided by the operating system which is more likely
    // going to be updated in a timely fashion. This overrides the default
    // path to the pem file bundled with Guzzle.
    'verify' => TRUE,
    'timeout' => 30,
    'headers' => [
      'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
    ],
    'handler' => $this->stack,
  ];
  $config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
  return new Client($config);
}