Fix header bug

Headers were not being successfully sent to the server, this fixes the bug and covers it with tests.