private static function getHeadersArray(array $serverVars): array
    {
        $headersArray = [];

        if (function_exists('getallheaders')) {
            /** @noinspection PhpComposerExtensionStubsInspection */
            return getallheaders();
        }

        foreach ($serverVars as $name => $value) {
            if (substr($name, 0, 5) === 'HTTP_') {
                $headersArray[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }

        return $headersArray;
    }