Adds a new option for the retry middleware allowing clients to give it a block that will say if a request should be retried or not - fixes #298