public function getHost()
    {
        if ($this->isUsingTrustedProxy() && $this->header->has(self::$trustedHeaderNames[RequestHeaderConstants::CLIENT_HOST])) {
            $hosts = explode(',', $this->header->get(self::$trustedHeaderNames[RequestHeaderConstants::CLIENT_HOST]));
            $host = trim(end($hosts));
        } else {
            $host = $this->header->get('X_FORWARDED_FOR');
        }

        $host = $this->getHostIfNull($host);

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

        // Check for forbidden characters
        if (!empty($host) && '' !== preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host)) {
            throw new \UnexpectedValueException("Invalid host $host");
        }

        return $host;
    }