Refactored the http client to avoid errors when recycling a connection