// NOTE : BaseUrl should have a final slash or the last Uri part is discarded. Also, // relative urls can *not* start with a slash. // Not exposed so that 3rd party code doesn't accidentally build a KeenHttpClient without // our handlers installed, which wouldn't be ideal. private static KeenHttpClient Create(Uri baseUrl, IHttpClientProvider httpClientProvider, Func <HttpMessageHandler> getHandlerChain) { if (!baseUrl.IsAbsoluteUri) { throw new ArgumentException( "The given base Url must be in the form of an absolute Uri.", nameof(baseUrl)); } // Delay actual creation of the handler chain by passing in a Func<> to create it. This // way if HttpClient already exists, we won't bother creating/modifying handlers. var httpClient = httpClientProvider.GetOrCreateForUrl( baseUrl, getHandlerChain, KeenHttpClientFactory.DEFAULT_HEADERS); var newClient = new KeenHttpClient(httpClient); return(newClient); }