WIP: decouple determination of headers from actual Flask code

Allows easier testing and better separation of concerns.