load HTML::Parser only if needed
additional server response check
use response lenght rather than content-type

Content-type header doesn't allow to distinguish between final response
in HTML format, and intermediate server response.
use tabs for indentation, for consistency