A lot of these lines to set common headers are repeated throughout the code.  Let's refactor these into a separate function in the file and just call the function.