Generalized middleware implementation for Ruby.