Add http chunked transfer support and refactor HTTP api