Simplifies debug logging function.
Fixes bug in test cases.

The test cases weren't checking the situation where a callback
was never called. This refactors those test cases into async
test cases.
Ensures content-length is set to the correct value.
Fixes bug in Iconv mechanism.