Add a method to generate headers before each request from a provided function

See #257