public static HttpClient GetHttpClient() { // we return a new instanceof httpclient beacause there // is no way to provide new http request message handler // for each request made and it makes mocking of network calls // impossible. So to circumvent, we simply return new instance for // for mocking purposes. if (ReturnHttpClientForMocks) { return(new HttpClient(HttpMessageHandlerFactory.GetMessageHandler(ReturnHttpClientForMocks))); } if (_client == null) { lock (LockObj) { if (_client == null) { _client = new HttpClient(HttpMessageHandlerFactory.GetMessageHandler(ReturnHttpClientForMocks)); } } } return(_client); }
private static HttpClient CreateHttpClient() { var httpClient = new HttpClient(HttpMessageHandlerFactory.GetMessageHandler(ReturnHttpClientForMocks)) { MaxResponseContentBufferSize = MaxResponseContentBufferSizeInBytes }; return(httpClient); }