/**
* 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")
class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterface {
/**
- * The HTTP Client
+ * The HTTP client.
*
* @var \GuzzleHttp\Client
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
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']);
}
/**
}
}
catch (RequestException $e) {
- throw new MigrateException('Error message: ' . $e->getMessage() . ' at ' . $url .'.');
+ throw new MigrateException('Error message: ' . $e->getMessage() . ' at ' . $url . '.');
}
return $response;
}