http plugin: Better error handling, and flush before shutdown