Guzzle settings (base_url, user agent) I'm searching a way to configure Drupal's HTTP Client Guzzle. I.e. the base_url and user agent.

The Guzzle docs provide info here: http://docs.guzzlephp.org/en/latest/quickstart.html#creating-a-client

But nothing that works with the Drupal implementation.

I can see in core/lib/Drupal/Core/Http/ClientFactory.php that there is a default config with which the Guzzle Client constructor is fed.

//Line 46-65:

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' =&gt; TRUE,
      'timeout' =&gt; 30,
      'headers' =&gt; [
        'User-Agent' =&gt; 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
      ],
      'handler' =&gt; $this-&gt;stack,
    ];

    $config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);

    return new Client($config);
  }


Any way to reconfigure this?

\Drupal::httpClient() does not provide any parameters for configuration.
There is no need to create your own Client or ClientFactory service.

Because ClientFactory::fromOptions() has

$config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);


You can specify default options to Guzzle for all clients created by Drupal via your settings.php.  Core only provides an example of proxy settings, but you could alter the user agent via

$settings['http_client_config']['headers']['User-Agent'] = 'Foobar 1.0';




To create a single client with different options, (which will override settings from both ClientFactory::fromOptions() and settings.php), you can use the factory service directly:

\Drupal::service('http_client_factory')-&gt;fromOptions([
  'headers' =&gt; ['User-Agent' =&gt; 'Foobar 1.0'],
]);