Implement inspect middleware.

Also allow middleware to be declared in the meta data.