ReverseProxyMiddleware::setSettingsOnRequest

public static ReverseProxyMiddleware::setSettingsOnRequest(Request $request, Settings $settings)

Sets reverse proxy settings on Request object.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A Request instance.

\Drupal\Core\Site\Settings $settings: The site settings.

File

core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php, line 58

Class

ReverseProxyMiddleware
Provides support for reverse proxies.

Namespace

Drupal\Core\StackMiddleware

Code

public static function setSettingsOnRequest(Request $request, Settings $settings) {
  // Initialize proxy settings.
  if ($settings->get('reverse_proxy', FALSE)) {
    $ip_header = $settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
    $request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $ip_header);

    $proto_header = $settings->get('reverse_proxy_proto_header', 'X_FORWARDED_PROTO');
    $request::setTrustedHeaderName($request::HEADER_CLIENT_PROTO, $proto_header);

    $host_header = $settings->get('reverse_proxy_host_header', 'X_FORWARDED_HOST');
    $request::setTrustedHeaderName($request::HEADER_CLIENT_HOST, $host_header);

    $port_header = $settings->get('reverse_proxy_port_header', 'X_FORWARDED_PORT');
    $request::setTrustedHeaderName($request::HEADER_CLIENT_PORT, $port_header);

    $forwarded_header = $settings->get('reverse_proxy_forwarded_header', 'FORWARDED');
    $request::setTrustedHeaderName($request::HEADER_FORWARDED, $forwarded_header);

    $proxies = $settings->get('reverse_proxy_addresses', array());
    if (count($proxies) > 0) {
      $request::setTrustedProxies($proxies);
    }
  }
}
doc_Drupal
2016-10-29 09:38:25
Comments
Leave a Comment

Please login to continue.