Fix error on calling addHeader under certain condition.

Any corrections are welcomed.