Commit f73dec81 authored by tmountjr's avatar tmountjr Committed by heddn

Issue #2931756 by tmountjr, edysmp, heddn: NULL headers causing error

parent 3c2c48ef
......@@ -58,6 +58,8 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->httpClient = \Drupal::httpClient();
// Ensure there is a 'headers' key in the configuration.
$configuration += ['headers' => []];
$this->setRequestHeaders($configuration['headers']);
}
......
......@@ -18,26 +18,45 @@ class HttpTest extends KernelTestBase {
/**
* Test http headers option.
*
* @dataProvider headerDataProvider
*/
function testHttpHeaders() {
$expected = [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
];
public function testHttpHeaders(array $definition, array $expected, array $preSeed = []) {
$http = new Http($definition, 'http', []);
$this->assertEquals($expected, $http->getRequestHeaders());
}
$configuration = [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
]
/**
* Provides multiple test cases for the testHttpHeaders method.
*
* @return array
* The test cases
*/
public function headerDataProvider() {
return [
'dummy headers specified' => [
'definition' => [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz',
],
],
'expected' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz',
],
],
'no headers specified' => [
'definition' => [
'no_headers_here' => 'foo',
],
'expected' => [],
],
];
$http = new Http($configuration, 'http', []);
$this->assertEquals($expected, $http->getRequestHeaders());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment