http-client: added support for chunked transfer encoding; code refactoring