refactored custom header/cookie support.