Added a guard against ContentType being null.
Moved the reporting about the HTTP/HTML charsets higher up the calling stack.
Shuffled some functions around, no structural changes.