class ReverseProxySubscriber

Reverse proxy subscriber for controller requests.

Hierarchy

Expanded class hierarchy of ReverseProxySubscriber

1 file declares its use of ReverseProxySubscriber
ReverseProxySubscriberUnitTest.php in drupal/core/tests/Drupal/Tests/Core/EventSubscriber/ReverseProxySubscriberUnitTest.php
Contains \Drupal\Core\EventSubscriber\ReverseProxySubscriberUnitTest.
1 string reference to 'ReverseProxySubscriber'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml

File

drupal/core/lib/Drupal/Core/EventSubscriber/ReverseProxySubscriber.php, line 18
Contains \Drupal\Core\EventSubscriber\ReverseProxySubscriber.

Namespace

Drupal\Core\EventSubscriber
View source
class ReverseProxySubscriber implements EventSubscriberInterface {

  /**
   * A settings object.
   *
   * @var \Drupal\Component\Utility\Settings
   */
  protected $settings;

  /**
   * Construct the ReverseProxySubscriber.
   *
   * @param \Drupal\Component\Utility\Settings $settings
   *   The read-only settings object of this request.
   */
  public function __construct(Settings $settings) {
    $this->settings = $settings;
  }

  /**
   * Passes reverse proxy settings to current request.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The Event to process.
   */
  public function onKernelRequestReverseProxyCheck(GetResponseEvent $event) {
    $request = $event
      ->getRequest();
    if ($this->settings
      ->get('reverse_proxy', 0)) {
      $reverse_proxy_header = $this->settings
        ->get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR');
      $request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $reverse_proxy_header);
      $reverse_proxy_addresses = $this->settings
        ->get('reverse_proxy_addresses', array());
      $request::setTrustedProxies($reverse_proxy_addresses);
    }
  }

  /**
   * Registers the methods in this class that should be listeners.
   *
   * @return array
   *   An array of event listener definitions.
   */
  static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = array(
      'onKernelRequestReverseProxyCheck',
      10,
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReverseProxySubscriber::$settings protected property A settings object.
ReverseProxySubscriber::getSubscribedEvents static function Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface::getSubscribedEvents
ReverseProxySubscriber::onKernelRequestReverseProxyCheck public function Passes reverse proxy settings to current request.
ReverseProxySubscriber::__construct public function Construct the ReverseProxySubscriber.