Add a middleware at a specified index

This allows to specify the index where the new middleware will be added.