def insert_after(after, new_middleware)
      @mutex.synchronize do
        return if @disabled_middleware.include?(new_middleware)
        return if @middlewares.include?(new_middleware)

        if after.is_a? Array
          index = @middlewares.rindex {|el| after.include?(el)}
        else
          index = @middlewares.rindex(after)
        end

        if index.nil?
          @middlewares << new_middleware
        else
          @middlewares.insert index + 1, new_middleware
        end
      end
    end
def insert_after(after, new_middleware)
      @mutex.synchronize do
        return if @disabled_middleware.include?(new_middleware)
        return if @middlewares.include?(new_middleware)

        if after.is_a? Array
          index = @middlewares.rindex {|el| after.include?(el)}
        else
          index = @middlewares.rindex(after)
        end

        if index.nil?
          @middlewares << new_middleware
        else
          @middlewares.insert index + 1, new_middleware
        end
      end
    end
Inserts a new middleware to use after a given middleware already added.

 Will return early if given middleware is disabled or already added.
 New middleware will be inserted last if the existing middleware is not already included.