class SimpletestHttpRequestSubscriber

Subscribe to HTTP requests and override the User-Agent header if the request is being dispatched from inside a simpletest.

Hierarchy

Expanded class hierarchy of SimpletestHttpRequestSubscriber

1 string reference to 'SimpletestHttpRequestSubscriber'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml

File

drupal/core/lib/Drupal/Core/Http/Plugin/SimpletestHttpRequestSubscriber.php, line 16
Contains Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber

Namespace

Drupal\Core\Http\Plugin
View source
class SimpletestHttpRequestSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return array(
      'request.before_send' => 'onBeforeSendRequest',
    );
  }

  /**
   * Event callback for request.before_send
   */
  public function onBeforeSendRequest(Event $event) {

    // If the database prefix is being used by SimpleTest to run the tests in a copied
    // database then set the user-agent header to the database prefix so that any
    // calls to other Drupal pages will run the SimpleTest prefixed database. The
    // user-agent is used to ensure that multiple testing sessions running at the
    // same time won't interfere with each other as they would if the database
    // prefix were stored statically in a file or database variable.
    $test_info =& $GLOBALS['drupal_test_info'];
    if (!empty($test_info['test_run_id'])) {
      $event['request']
        ->setHeader('User-Agent', drupal_generate_test_ua($test_info['test_run_id']));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpletestHttpRequestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
SimpletestHttpRequestSubscriber::onBeforeSendRequest public function Event callback for request.before_send