Kocal
New member
- Affected version
- 2.1.3
Hi
I'm facing an issue when trying to create a new Guzzle HTTP client with default headers.
Then when using the client, I found that header
I've put some
After some investigation, the issue is coming from the method
As a workaround, I modified the line with the following code and it works as expected:
Thanks!
I'm facing an issue when trying to create a new Guzzle HTTP client with default headers.
PHP:
<?php
// config.php
$config['container']['my-api-client'] = function (\XF\Container $c) {
return $c['http']->createClient([
'base_uri' => 'http://example.com',
'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: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:
PHP:
<?php
$options['headers'] = array_merge(
['User-Agent' => 'XenForo/2.x (' . $xfOptions->boardUrl . ')'],
isset($options['headers']) && is_array($options['headers']) ? $options['headers'] : []
);
Thanks!