/// <summary> /// Construct an IKeenHttpClient for the given base URL, configured with an HttpClient that /// is retrieved and/or stored in the given IHttpClientProvider. If necessary, the /// HttpClient is created and configured with the default set of HTTP handlers. /// /// <seealso cref="KeenHttpClientFactory.CreateDefaultHandlerChain"/> /// /// </summary> /// <param name="baseUrl">The base URL for the constructed IKeenHttpClient.</param> /// <param name="httpClientProvider">The provider used to retrieve the HttpClient.</param> /// <returns>A new IKeenHttpClient for the given base URL.</returns> public static IKeenHttpClient Create(Uri baseUrl, IHttpClientProvider httpClientProvider) { return(KeenHttpClientFactory.Create( baseUrl, httpClientProvider, () => KeenHttpClientFactory.CreateDefaultHandlerChain())); }
/// <summary> /// Construct an IKeenHttpClient for the given base URL, configured with an HttpClient that /// is retrieved and/or stored in the given IHttpClientProvider, and if necessary, /// configured with the given HTTP handlers. /// /// <seealso cref="KeenHttpClientFactory.CreateHandlerChain"/> /// /// </summary> /// <param name="baseUrl">The base URL for the constructed IKeenHttpClient.</param> /// <param name="httpClientProvider">The provider used to retrieve the HttpClient.</param> /// <param name="innerHandler">HTTP handler terminating the handler chain.</param> /// <param name="handlers">Handlers to be chained in the pipeline.</param> /// <returns>A new IKeenHttpClient for the given base URL.</returns> public static IKeenHttpClient Create(Uri baseUrl, IHttpClientProvider httpClientProvider, HttpClientHandler innerHandler, params DelegatingHandler[] handlers) { return(KeenHttpClientFactory.Create( baseUrl, httpClientProvider, () => KeenHttpClientFactory.CreateHandlerChain(innerHandler, handlers))); }
/// <summary> /// Create an HttpMessageHandler representing the handler pipeline. We will construct the /// HTTP handler pipeline such that provided handlers are called in order for requests, and /// receive responses in reverse order. Keen internal handlers will defer to the first /// DelegatingHandler and the pipeline will terminate at our HttpClientHandler or to the /// given HttpClientHandler if present, in case client code wants to do something like use /// WebRequestHandler functionality or otherwise add custom behavior. /// </summary> /// <param name="innerHandler">Terminating HttpClientHandler.</param> /// <param name="handlers">Handlers to be chained in the pipeline.</param> /// <returns>The entire handler chain.</returns> public static HttpMessageHandler CreateHandlerChain(HttpClientHandler innerHandler, params DelegatingHandler[] handlers) { // We put our handlers first. Client code can look at the final state of the request // this way. Overwriting built-in handler state is shooting oneself in the foot. IEnumerable <DelegatingHandler> intermediateHandlers = KeenHttpClientFactory.CreateDefaultDelegatingHandlers().Concat(handlers); return(KeenHttpClientFactory.CreateHandlerChainInternal(innerHandler, intermediateHandlers)); }
/// <summary> /// Construct an IKeenHttpClient for the given base URL, configured with an HttpClient that /// is retrieved and/or stored in the given IHttpClientProvider, and if necessary, /// configured with the given HTTP handlers in a lazy fashion only if construction is /// necessary. Note that the given handler factory function could be called under a lock, /// so care should be taken in multi-threaded scenarios. /// /// <seealso cref="KeenHttpClientFactory.CreateHandlerChain"/> /// /// </summary> /// <param name="baseUrl">The base URL for the constructed IKeenHttpClient.</param> /// <param name="httpClientProvider">The provider used to retrieve the HttpClient.</param> /// <param name="getHandlers">A factory function called if construction of the HttpClient /// is necessary. It should return an optional HttpClientHandler to terminate the /// handler chain, as well as an optional list of intermediate HTTP handlers to be /// chained in the pipeline.</param> /// <returns>A new IKeenHttpClient for the given base URL.</returns> public static IKeenHttpClient Create( Uri baseUrl, IHttpClientProvider httpClientProvider, Func <Tuple <HttpClientHandler, IEnumerable <DelegatingHandler> > > getHandlers) { Func <HttpMessageHandler> getHandlerChain = () => { Tuple <HttpClientHandler, IEnumerable <DelegatingHandler> > handlers = getHandlers?.Invoke(); return(KeenHttpClientFactory.CreateHandlerChainInternal(handlers.Item1, handlers.Item2)); }; return(KeenHttpClientFactory.Create( baseUrl, httpClientProvider, getHandlerChain)); }
/// <summary> /// Create an HttpMessageHandler representing the handler pipeline. We will construct the /// HTTP handler pipeline such that provided handlers are called in order for requests, and /// receive responses in reverse order. Keen internal handlers will defer to the first /// DelegatingHandler and the pipeline will terminate at our HttpClientHandler. /// </summary> /// <param name="handlers">Handlers to be chained in the pipeline.</param> /// returns>The entire handler chain.</returns> public static HttpMessageHandler CreateHandlerChain(params DelegatingHandler[] handlers) { return(KeenHttpClientFactory.CreateHandlerChain(null, handlers)); }
/// <summary> /// Create the default handler pipeline with only Keen internal handlers installed. /// </summary> /// returns>The default handler chain.</returns> public static HttpMessageHandler CreateDefaultHandlerChain() { return(KeenHttpClientFactory.CreateHandlerChainInternal( null, KeenHttpClientFactory.CreateDefaultDelegatingHandlers())); }
/// <summary> /// Given a base URL, return an IKeenHttpClient against which requests can be made. /// </summary> /// <param name="baseUrl">The base URL, e.g. https://api.keen.io/3.0/ </param> /// <returns>An IKeenHttpClient configured to handle requests to resources relative to the /// given base URL.</returns> public IKeenHttpClient GetForUrl(Uri baseUrl) { var keenHttpClient = KeenHttpClientFactory.Create(baseUrl, HttpClientCache.Instance); return(keenHttpClient); }