Middleware

Yes your proposal is much better ... here my pull request