extract common httpclient functionality