Added a check for headers before parsing them

I did not check if this is a result of a bad change somewhere else, so this will need context review by a veteran.