Pass req to callback

Check the arity of the callback functions and pass the `req`
object if it has an extra parameter. This should be backwards
compatible with any existing plugins.