Commit 2b2b97d2 authored by catch's avatar catch

Issue #2168809 by sun, damiankloip: Do not add the Guzzle HTTP client request...

Issue #2168809 by sun, damiankloip: Do not add the Guzzle HTTP client request subscriber outside of test environment.
parent 3de51022
......@@ -179,10 +179,6 @@ services:
class: Drupal\Core\Http\Client
tags:
- { name: service_collector, tag: http_client_subscriber, call: attach }
http_client_simpletest_subscriber:
class: Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
tags:
- { name: http_client_subscriber }
theme.negotiator:
class: Drupal\Core\Theme\ThemeNegotiator
arguments: ['@access_check.theme', '@request_stack']
......
......@@ -48,6 +48,7 @@ public function register(ContainerBuilder $container) {
$container->addScope(new Scope('request'));
$this->registerTwig($container);
$this->registerUuid($container);
$this->registerTest($container);
// Add the compiler pass that lets service providers modify existing
// service definitions. This pass must come first so that later
......@@ -143,4 +144,18 @@ public static function registerUuid(ContainerBuilder $container) {
return $uuid_class;
}
/**
* Registers services and event subscribers for a site under test.
*/
protected function registerTest(ContainerBuilder $container) {
// Do nothing if we are not in a test environment.
if (!drupal_valid_test_ua()) {
return;
}
// Add the HTTP request subscriber to Guzzle.
$container
->register('test.http_client.request_subscriber', 'Drupal\Core\Test\EventSubscriber\HttpRequestSubscriber')
->addTag('http_client_subscriber');
}
}
......@@ -2,26 +2,25 @@
/**
* @file
* Contains Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
* Contains \Drupal\Core\Test\EventSubscriber\HttpRequestSubscriber.
*/
namespace Drupal\Core\Http\Plugin;
namespace Drupal\Core\Test\EventSubscriber;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Event\SubscriberInterface;
/**
* Subscribe to HTTP requests and override the User-Agent header if the request
* is being dispatched from inside a simpletest.
* Overrides the User-Agent HTTP header for outbound HTTP requests.
*/
class SimpletestHttpRequestSubscriber implements SubscriberInterface {
class HttpRequestSubscriber implements SubscriberInterface {
/**
* {@inheritdoc}
*/
public function getEvents() {
return array(
'before' => array('onBeforeSendRequest'),
'before' => array('onBeforeSendRequest'),
);
}
......@@ -39,4 +38,5 @@ public function onBeforeSendRequest(BeforeEvent $event) {
$event->getRequest()->setHeader('User-Agent', drupal_generate_test_ua($test_prefix));
}
}
}
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