Make the middleware functions more generic.

Instead of allowing middleware actions to be performed in the inner
monad, let it build the new response in RequestT.