protected function getHttpHeaders(string $prefix = null): array
    {
        $headers = [];

        // Get all headers
        if (function_exists('\getallheaders')) {
            $headers = \getallheaders() ?: [];
        } else {
            foreach ($_SERVER as $name => $value) {
                if (substr($name, 0, 5) == 'HTTP_') {
                    $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
                } else {
                    if ($name === 'CONTENT_TYPE') {
                        $headers['Content-Type'] = $value;
                    }
                }
            }
        }

        // Headers filter
        if (!empty($prefix)) {
            $prefixLength = mb_strlen($prefix);

            $headers =
                array_filter(
                    $headers,
                    function ($key) use ($prefix, $prefixLength) {
                        return substr($key, 0, $prefixLength) == $prefix;
                    }, ARRAY_FILTER_USE_KEY);
        }

        return $headers;
    }