public function Request::getHost

Same name in this branch

Returns the host name.

@api

Return value

string

1 call to Request::getHost()
Request::getHttpHost in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php
Returns the HTTP host being requested.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php, line 880

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getHost() {
  if (self::$trustProxy && ($host = $this->headers
    ->get('X_FORWARDED_HOST'))) {
    $elements = explode(',', $host);
    $host = trim($elements[count($elements) - 1]);
  }
  else {
    if (!($host = $this->headers
      ->get('HOST'))) {
      if (!($host = $this->server
        ->get('SERVER_NAME'))) {
        $host = $this->server
          ->get('SERVER_ADDR', '');
      }
    }
  }

  // Remove port number from host
  $host = preg_replace('/:\\d+$/', '', $host);

  // host is lowercase as per RFC 952/2181
  return trim(strtolower($host));
}