Return HTTP protocol version (X.Y)

@param array $server The SERVER environment variable

@return string
328242
private static function _marshalProtocolVersion($server)
    {
        if (!isset($server['SERVER_PROTOCOL'])) {
            return '1.1';
        }

        if (!preg_match(
            '#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#',
            $server['SERVER_PROTOCOL'], $matches
        )
        ) {
            throw new UnexpectedValueException(
                sprintf(
                    'Unrecognized protocol version (%s)',
                    $server['SERVER_PROTOCOL']
                )
            );
        }

        return $matches['version'];
    }
772005
def do_version():
    """"""
    v = ApiPool.ping.model.Version(
        name=ApiPool().current_server_name,
        version=ApiPool().current_server_api.get_version(),
        container=get_container_version(),
    )
    log.info("/version: " + pprint.pformat(v))
    return v
67171
public function parseUrl(array $server) {
        $protocol = array_has($server, 'HTTPS') ? 'https' : 'http';
        $host = array_get($server, 'HTTP_HOST');
        $uri = array_get($server, 'REQUEST_URI');

        return new Url(s('%s://%s%s', $protocol, $host, $uri));
    }
6284
public static function getHeadersFromServer(array $server): array
    {
        $headers = [];
        foreach ($server as $key => $value) {
            // Apache prefixes environment variables with REDIRECT_
            // if they are added by rewrite rules
            if (0 === \strpos($key, 'REDIRECT_')) {
                $key = \substr($key, 9);

                // We will not overwrite existing variables with the
                // prefixed versions, though
                if (\array_key_exists($key, $server)) {
                    continue;
                }
            }

            if ($value && 0 === \strpos($key, 'HTTP_')) {
                $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
                $headers[$name] = $value;

                continue;
            }

            if ($value && 0 === \strpos($key, 'CONTENT_')) {
                $name = 'content-'.\strtolower(\substr($key, 8));
                $headers[$name] = $value;

                continue;
            }
        }

        return $headers;
    }
1105073
public static function getSymfonyVersion($version)
    {
        return implode('.', \array_slice(array_map(static function ($val) {
            return (int) $val;
        }, explode('.', $version)), 0, 3));
    }
186904
public function server(array $server)
    {
        parent::server($server);

        $this->server = $server;

        $this->method = $server['REQUEST_METHOD'];

        $this->target = $server['REQUEST_URI'];

        $http = 'https://';

        if (! isset($server['HTTPS']) || $server['HTTPS'] === 'off')
        {
            $http = 'http://';
        }

        $link = $http . $server['SERVER_NAME'];

        $port = $server['SERVER_PORT'] . $this->target;

        $this->uri = new Uri($link . ':' . $port);

        return $this;
    }
510911
private function determineRemoteIpAddress(array $server): string
    {
        if (array_key_exists('HTTP_X_FORWARDED_FOR', $server) && filter_var($server['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) {
            return $server['HTTP_X_FORWARDED_FOR'];
        } elseif (array_key_exists('HTTP_CLIENT_IP', $server) && filter_var($server['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) {
            return $server['HTTP_CLIENT_IP'];
        } elseif (array_key_exists('HTTP_TRUE_CLIENT_IP', $server) && filter_var($server['HTTP_TRUE_CLIENT_IP'], FILTER_VALIDATE_IP)) {
            return $server['HTTP_TRUE_CLIENT_IP'];
        }

        return $server['REMOTE_ADDR'];
    }
608459
public function getServerVersion() : string
    {
        return (is_array($this->apache_info) && array_key_exists('server-version', $this->apache_info))
                ? $this->apache_info['server-version']
                : 'Unknown'
        ;
    }
789367
public static function getWebServerSoftWare() : string
    {
        static $type;

        if (isset($type)) {
            return $type;
        }

        $software = isset($_SERVER['SERVER_SOFTWARE'])
            ? $_SERVER['SERVER_SOFTWARE']
            : null;

        $type = self::SERVER_TYPE_UNKNOWN;

        if (stripos($software, 'lighttpd') !== false) {
            $type = self::SERVER_TYPE_LIGHTTPD;
        }

        if (strpos($software, 'Hiawatha') !== false) {
            $type = self::SERVER_TYPE_HIAWATHA;
        }

        if (strpos($software, 'Apache') !== false) {
            $type = self::SERVER_TYPE_APACHE;
        } elseif (strpos($software, 'Litespeed') !== false) {
            $type = self::SERVER_TYPE_LITESPEED;
        }

        if (strpos($software, 'nginx') !== false) {
            $type = self::SERVER_TYPE_NGINX;
        }

        if ($type !== self::SERVER_TYPE_APACHE && $type !== self::SERVER_TYPE_LITESPEED
            && strpos($software, 'Microsoft-IIS') !== false
            && strpos($software, 'ExpressionDevServer') !== false
        ) {
            $type = self::SERVER_TYPE_IIS;
            if (intval(substr($software, strpos($software, 'Microsoft-IIS/')+14)) >= 7) {
                $type = self::SERVER_TYPE_IIS7;
            }
        }
        if (function_exists('apache_get_modules')) {
            if (in_array('mod_security', apache_get_modules())) {
                $type = self::SERVER_TYPE_APACHE;
            }

            if ($type == self::SERVER_TYPE_UNKNOWN && function_exists('apache_get_version')) {
                $type = self::SERVER_TYPE_APACHE;
            }
        }

        return $type;
    }
723535
public function getServerCfg($server)
    {
        if (!isset($this->servers[$server])) {
            throw new \Erebot\NotFoundException('No such server');
        }
        return $this->servers[$server];
    }
288798
public function getServerVersion()
    {
        $serverInfos = $this->conn->get_server_info();
        if (stripos($serverInfos, 'mariadb') !== false) {
            return $serverInfos;
        }

        $majorVersion = floor($this->conn->server_version / 10000);
        $minorVersion = floor(($this->conn->server_version - $majorVersion * 10000) / 100);
        $patchVersion = floor($this->conn->server_version - $majorVersion * 10000 - $minorVersion * 100);

        return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
    }
150277
protected function getHttpProtocol()
    {
        if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
            if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
                return 'https';
            }

            return 'http';
        }

        /*apache + variants specific way of checking for https*/
        if (isset($_SERVER['HTTPS']) &&
            ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
            return 'https';
        }

        /*nginx way of checking for https*/
        if (isset($_SERVER['SERVER_PORT']) &&
            ($_SERVER['SERVER_PORT'] === '443')) {
            return 'https';
        }

        return 'http';
    }
130180
private static function aggregateUriFromServer($server)
    {
        $uri = new Uri();

        $scheme = 'http';
        $uri = $uri->withScheme($scheme);

        if (isset($server['SERVER_NAME'])) {
            $uri = $uri->withHost($server['SERVER_NAME']);
        }

        if (isset($server['SERVER_PORT'])) {
            $uri = $uri->withPort((int)$server['SERVER_PORT']);
        }

        if (isset($server['REQUEST_URI'])) {
            $q = explode('?', $server['REQUEST_URI']);

            if (isset($q[0])) {
                $uri = $uri->withPath($q[0]);
            }
        }

        if (isset($server['QUERY_STRING'])) {
            $uri = $uri->withQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
680091
public function getVersionString() {
        if ($this->versionString === null) {
            if (!$this->isConnected())
                $this->connect();
            $this->versionString = mysql_get_server_info($this->hConnection);
        }
        return $this->versionString;
    }
1016627
public function getClientVersion()
    {
        $this->_connect();

        $version  = $this->_connection->server_version;
        $major    = (int)($version / 10000);
        $minor    = (int)($version % 10000 / 100);
        $revision = (int)($version % 100);

        return $major . '.' . $minor . '.' . $revision;
    }
139545
public static function getMethod(array $server): string
    {
        $method = $server['REQUEST_METHOD'] ?? 'GET';
        if ($method === 'POST' &&
            isset(
                $server['HTTP_X_HTTP_METHOD_OVERRIDE'],
                self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
            )
        ) {
            $method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
        }

        return $method;
    }
31119
private static function serverToHeaders(array $server)
    {
        $headers = array();
        foreach ($server as $key => $value) {
            if (strpos($key, 'HTTP_') === 0) {
                $key = strtolower(str_replace("_", '-', substr($key, 5)));
                $headers[$key] = $value;
            }
        }
        return $headers;
    }