Fixed Can't set default headers for Guzzle when calling XF\SubContainer\Http#createClient


New member
Affected version
Hi :)

I'm facing an issue when trying to create a new Guzzle HTTP client with default headers.

// config.php

$config['container']['my-api-client'] = function (\XF\Container $c) {
    return $c['http']->createClient([
        'base_uri' => '',
        'headers'  => [
            'Authorization' => 'the api key',

Then when using the client, I found that header Authorization was not present inside the final configuration.
I've put some dump() and this is what happens:
Capture d’écran de 2019-09-05 08-40-01.png

After some investigation, the issue is coming from the method applyDefaultClientOptions at line $options['headers'] = ['User-Agent' => 'XenForo/2.x (' . $xfOptions->boardUrl . ')'];, which simply define a new headers array over an existing one.

As a workaround, I modified the line with the following code and it works as expected:
$options['headers'] = array_merge(
    ['User-Agent' => 'XenForo/2.x (' . $xfOptions->boardUrl . ')'],
    isset($options['headers']) && is_array($options['headers']) ? $options['headers'] : []


XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.4).

Change log:
When setting http client defaults, do not overwrite existing headers that have been passed in.
Any changes made as a result of this issue being resolved may not be rolled out here until later.