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

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

        @middlewares.insert index || @middlewares.length, new_middleware
      end
    end
def insert_before(before, new_middleware)
      @mutex.synchronize do
        return if @disabled_middleware.include?(new_middleware)
        return if @middlewares.include?(new_middleware)

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

        @middlewares.insert index || @middlewares.length, new_middleware
      end
    end
Inserts a new middleware to use before 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.