Improved documentation and error handling

This ensures that things like setting null headers as reported in #1403 are easier to debug.
Merge pull request #1408 from jroper/1403-null-header

Improved documentation and error handling