Improve null handling when adding custom header

pull-request for issue #971