private function withSessionCookie(ResponseInterface $response, string $session_id): ResponseInterface
    {
        // Merge session cookie options.
        $default = session_get_cookie_params();

        $default = array_change_key_case($default, CASE_LOWER);
        $options = array_change_key_case($this->options, CASE_LOWER);

        $options = array_merge($default, $options);

        if ($options['lifetime'] < 0) $options['lifetime'] = 0;

        // Create a session cookie and attach it to the response.
        $cookie = SetCookie::create($this->name, $session_id)
            ->withMaxAge($options['lifetime'])
            ->withPath($options['path'])
            ->withDomain($options['domain'])
            ->withSecure($options['secure'])
            ->withHttpOnly($options['httponly']);

        if ($options['lifetime'] > 0) {

            $cookie = $cookie->withExpires(time() + $options['lifetime']);

        }

        return FigResponseCookies::set($response, $cookie);
    }