allow redirect to be a function

discussed as an addition to #482