explicitly check the headers to find out if we already set it

Under certain conditions the old check would wrongly report "already set".