3 namespace Drupal\Core\Http;
5 use Drupal\Component\Utility\NestedArray;
6 use Drupal\Core\Site\Settings;
8 use GuzzleHttp\HandlerStack;
11 * Helper class to construct a HTTP client with Drupal specific config.
18 * @var \GuzzleHttp\HandlerStack
23 * Constructs a new ClientFactory instance.
25 * @param \GuzzleHttp\HandlerStack $stack
28 public function __construct(HandlerStack $stack) {
29 $this->stack = $stack;
33 * Constructs a new client object from some configuration.
35 * @param array $config
36 * The config for the client.
38 * @return \GuzzleHttp\Client
41 public function fromOptions(array $config = []) {
43 // Security consideration: we must not use the certificate authority
44 // file shipped with Guzzle because it can easily get outdated if a
45 // certificate authority is hacked. Instead, we rely on the certificate
46 // authority file provided by the operating system which is more likely
47 // going to be updated in a timely fashion. This overrides the default
48 // path to the pem file bundled with Guzzle.
52 'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
54 'handler' => $this->stack,
55 // Security consideration: prevent Guzzle from using environment variables
56 // to configure the outbound proxy.
64 $config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
66 return new Client($config);