Implemented middleware option

Please merge this missing feature.