Refactor Accept header handling for safer code paths

Based on feedback from @nuttycom and @dcsobral