Commit 25244364 authored by heddn's avatar heddn

Issue #2921708 by edysmp, drclaw, CrashTest_, heddn: Allow creation of custom headers without auth

parent 65848b6a
......@@ -10,6 +10,19 @@ use GuzzleHttp\Exception\RequestException;
/**
* Retrieve data over an HTTP connection for migration.
*
* * Example:
*
* @code
* source:
* plugin: url
* data_fetcher_plugin: http
* headers:
* Accept: application/json
* User-Agent: Internet Explorer 6
* Authorization-Key: secret
* Arbitrary-Header: foobarbaz
* @endcode
*
* @DataFetcher(
* id = "http",
* title = @Translation("HTTP")
......@@ -44,6 +57,8 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->httpClient = \Drupal::httpClient();
$this->setRequestHeaders($configuration['headers']);
}
/**
......
<?php
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_fetcher;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\Http;
use Drupal\Tests\Core\Test\KernelTestBaseTest;
use Drupal\Tests\UnitTestCase;
/**
* Class HttpTest
*
* @group migrate_plus
* @package Drupal\Tests\migrate_plus\Unit\migrate_plus\data_fetcher
*/
class HttpTest extends KernelTestBase {
/**
* Test http headers option.
*/
function testHttpHeaders() {
$expected = [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
];
$configuration = [
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Internet Explorer 6',
'Authorization-Key' => 'secret',
'Arbitrary-Header' => 'foobarbaz'
]
];
$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