Get headers from $_SERVER.

@param   array $server The $_SERVER superglobal variable.

@return  array
8665
public static function prepareHeaders(array $server)
    {
        $headers = [];

        foreach ($server as $key => $value) {
            if ($value && strpos($key, 'HTTP_') === 0) {
                $name = strtr(substr($key, 5), '_', ' ');
                $name = strtr(ucwords(strtolower($name)), ' ', '-');
                $name = strtolower($name);

                $headers[$name] = $value;

                continue;
            }

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

                $headers[$name] = $value;

                continue;
            }
        }

        return $headers;
    }
792933
private function getAllHeaders()
    {
        $headers = [];
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                $headers[$name] = $value;
            } else {
                if ($name == "CONTENT_TYPE") {
                    $headers["Content-Type"] = $value;
                } else {
                    if ($name == "CONTENT_LENGTH") {
                        $headers["Content-Length"] = $value;
                    }
                }
            }
        }

        return $headers;
    }
955044
protected function getHeaders()
    {
        if (function_exists('getallheaders')) {
            return getallheaders();
        }
        $arr_headers = [];
        foreach ($_SERVER as $str_key => $str_value) {
            if (strpos($str_key, 'HTTP_') === 0) {
                $arr_headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($str_key, 5)))))] = $str_value;
            }
        }
        return $arr_headers;
    }
329735
private static function getHeadersFromInput ()
	{
		// getallheaders available, use that
		if (function_exists('getallheaders')) return getallheaders();

		// getallheaders not available: manually extract 'm
		$headers = [];
		foreach ($_SERVER as $name => $value)
		{
			if (substr($name, 0, 5) == 'HTTP_') {
			    $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
				$headers[$key] = $value;
			} else if (strtolower (substr ($name, 0, 7)) == 'content') {
                $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $name))));
				$headers[$key] = $value;
			}
		}
		return $headers;
	}
1178874
protected function getAllHeaders()
    {
        $headers = [];

        foreach ($_SERVER as $key => $value) {
            if (substr($key, 0, 5) == 'HTTP_') {
                $key = substr($key, 5);
                $key = str_replace('_', ' ', strtolower($key));
                $key = str_replace(' ', '-', ucwords($key));

                $headers[$key] = $value;
            }
        }

        return $headers;
    }
444699
private static function getHeaders($recognizedHeaders)
    {
        $headers = array();

        foreach ($recognizedHeaders as $header) {
            if (isset($_SERVER[$header])) {
                $headers[] = $header;
            }
        }

        return $headers;
    }
1297630
protected function setHeaders(array $server)
        {
            $headers = [];

            if (!isset($server['authorization'])) {
                $allHeaders = array_change_key_case(getallheaders(), CASE_LOWER);
                if (isset($allHeaders['authorization'])) {
                    $name = $this->setHeaderName('HTTP_AUTHORIZATION');
                    $headers[$name] =  [
                        'original' => 'HTTP_AUTHORIZATION', 
                        'values'   => [$allHeaders['authorization']]
                    ];
                }
            }
            
            foreach ($server as $key => $value) {
                if(in_array($key, $this->special) || substr($key, 0, 5) == 'HTTP_') {
                    
                    $name = $this->setHeaderName($key);
                    $headers[$name] =  [
                        'original' => $key, 
                        'values'   => [$value]
                    ];
                }
            }
            return $headers;
        }
723535
public function getServerCfg($server)
    {
        if (!isset($this->servers[$server])) {
            throw new \Erebot\NotFoundException('No such server');
        }
        return $this->servers[$server];
    }
893666
public static function GetRequestHeaders()
	{

		if (function_exists('getallheaders')) return getallheaders();

		$headers = array();
		foreach ($_SERVER as $k => $v)
		{
			if (substr($k, 0, 5) == "HTTP_")
			{
				$k = str_replace('_', ' ', substr($k, 5));
				$k = str_replace(' ', '-', ucwords(strtolower($k)));
				$headers[$k] = $v;
			}
		}
		return $headers;
	}
1134418
private function getRedisServers(array $servers)
    {
        if (!empty($servers)) {
            foreach ($servers as $server) {
                if (isset($server['socket'])) {
                    $server = [
                        'server' => array_get($server, 'socket', ''),
                        'ttl' => array_get($server, 'ttl', null),
                    ];
                } else {
                    $host = array_get($server, 'host', '');
                    // Check for both server/host - fallback due to cache using server
                    $host = !empty($host) ?: array_get($server, 'server', '127.0.0.1');
                    $server = [
                        'server' => $host,
                        'port' => array_get($server, 'port', 11211),
                        'ttl' => array_get($server, 'ttl', null),
                    ];
                }
                yield $server;
            }
        } else {
            yield ['server' => '127.0.0.1', 'port' => '6379', 'ttl' => 0.5];
        }
    }
1296435
private static function aggregateHttpProtocolVersionFromServer($server)
    {
        if (!isset($server['SERVER_PROTOCOL'])) {
            return null;
        }

        $pattern = '/^(?P<scheme>HTTP)\/(?P<protocol_version>1\.(0|1))$/';

        if (!preg_match($pattern, $server['SERVER_PROTOCOL'], $q)) {
            return null;
        }

        return $q['protocol_version'];
    }
177423
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

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

        return $uri;
    }
693924
protected function getHeadersFromServerArr(array $server) : array
    {
        $headers = [];
        $specialKeys = [
            'CONTENT_TYPE'   => 'Content-Type',
            'CONTENT_LENGTH' => 'Content-Length',
        ];
        foreach ($server as $key => $value) {
            if (substr($key, 0, 5) === 'HTTP_') {
                $header = str_replace(' ', '-',
                    ucwords(str_replace('_', ' ', strtolower(substr($key, 5))))
                );
                $headers[$header] = $value;
            } elseif (isset($specialKeys[$key])) {
                $headers[$specialKeys[$key]] = $value;
            }
        }
        
        if (!isset($headers['Authorization']) && isset($server['REDIRECT_HTTP_AUTHORIZATION'])) {
            $headers['Authorization'] = $server['REDIRECT_HTTP_AUTHORIZATION'];
        }
        
        if (isset($server['PHP_AUTH_USER'])) {
            $headers['PHP_AUTH_USER'] = $server['PHP_AUTH_USER'];
            $headers['PHP_AUTH_PW'] = $server['PHP_AUTH_PW'] ?? '';
        }
        
        return $headers;
    }
673334
protected function findAuthHeader(array $server) {
        if (array_has($server, 'HTTP_AUTHORIZATION')) {
            return array_get($server, 'HTTP_AUTHORIZATION');
        } else if (array_has($server, 'REDIRECT_HTTP_AUTHORIZATION')) {
            return array_get($server, 'REDIRECT_HTTP_AUTHORIZATION');
        }

        return null;
    }
637701
public static function getHostAndPortFromArray(array $server): array
    {
        if (isset($server['HTTP_HOST'])) {
            return self::getHostAndPortFromHost($server['HTTP_HOST']);
        }

        if (!isset($server['SERVER_NAME'])) {
            return ['', null];
        }

        $host = $server['SERVER_NAME'];
        $port = null;
        if (isset($server['SERVER_PORT'])) {
            $port = (int) $server['SERVER_PORT'];
        }

        // Misinterpreted IPv6-Address
        // Reported for Safari on Windows
        if (isset($server['SERVER_ADDR']) && \preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
            $host = '[' . $server['SERVER_ADDR'] . ']';
            $port = $port ?: 80;
            if ($port . ']' === \substr($host, \strrpos($host, ':') + 1)) {
                // The last digit of the IPv6-Address has been taken as port
                // Unset the port so the default port can be used
                $port = null;
            }
        }

        return [$host, $port];
    }
806348
public static function make(array $server = null)
    {
        if (empty($server)) {
            $server = $_SERVER;
        }

        if (isset($server['SERVER_PROTOCOL'])) {
            return $server['SERVER_PROTOCOL'];
        }

        return 'HTTP/1.1';
    }
163114
def get_headers(server):
    """"""
    try:
        response = requests.head(
            server, allow_redirects=False, verify=False, timeout=5)
    except requests.exceptions.ConnectionError:
        return False

    return dict(response.headers)