public static RestClientFactoryConfig UseFormUrlEncodedHandler(this RestClientFactoryConfig config) { DelegatingHandler HandlerFactory() => new FormUrlEncodedHandler(); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseHandler(this RestClientFactoryConfig config, Func <HttpRequestMessage, CancellationToken, Func <HttpRequestMessage, CancellationToken, Task <HttpResponseMessage> >, Task <HttpResponseMessage> > handler) { DelegatingHandler HandlerFactory() => new DelegatingHandlerWrapper(handler); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseUnitTestHandler(this RestClientFactoryConfig config, Action <HttpRequestMessage> handler) { DelegatingHandler HandlerFactory() => new UnitTestHandler(handler); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseTwitterHandler(this RestClientFactoryConfig config, string consumerKey, string consumerKeySecret, string accessToken, string accessTokenSecret) { DelegatingHandler HandlerFactory() => new TwitterHandler(consumerKey, consumerKeySecret, accessToken, accessTokenSecret); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseRetryHandler(this RestClientFactoryConfig config, int maxRetries, double waitToRetryInSeconds, double maxWaitToRetryInSeconds, RetryHandler.BackOffStrategy backOffStrategy) { DelegatingHandler HandlerFactory() => new RetryHandler(maxRetries, waitToRetryInSeconds, maxWaitToRetryInSeconds, backOffStrategy); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseMultipartFormDataHandler(this RestClientFactoryConfig config) { DelegatingHandler HandlerFactory() => new MultipartFormDataHandler(); config.HttpClientBuilder.AddHttpMessageHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseCookieHandler(this RestClientFactoryConfig config, CookieContainer cookieContainer) { config.UseHttpClientHandler(httpClientHandler => { httpClientHandler.CookieContainer = cookieContainer; }); DelegatingHandler HandlerFactory() => new CookieHandler(); config.UseHandler(HandlerFactory); return(config); }
public static RestClientFactoryConfig UseHttpClientHandler(this RestClientFactoryConfig config, Action <HttpClientHandler> httpClientHandlerOptions) { HttpClientHandler ConfigureHttpClientHandler(IServiceProvider provider) // Delegate called at Factory creation time { var clientHandler = provider.GetRequiredService <HttpClientHandlerWrapper>(); httpClientHandlerOptions(clientHandler); return(clientHandler); } config.HttpClientBuilder.Services.TryAddTransient <HttpClientHandlerWrapper>(); config.HttpClientBuilder.ConfigurePrimaryHttpMessageHandler(ConfigureHttpClientHandler); return(config); }
public static RestClientFactoryConfig AddRestClient(this IServiceCollection services, string name, string baseUri, Headers defaultRequestHeaders) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name cannot be empty", nameof(name)); } services.TryAddSingleton <IRestClientFactory, RestClientFactory>(); var httpClientBuilder = services.AddHttpClient(name); var config = new RestClientFactoryConfig(httpClientBuilder); services.AddSingleton(serviceProvider => new RestClientContainer(serviceProvider, name, baseUri, defaultRequestHeaders)); return(config); }
public static RestClientFactoryConfig UseHttpClientHandler(this RestClientFactoryConfig config, Func <HttpClientHandler> handler) { config.HttpClientBuilder.ConfigurePrimaryHttpMessageHandler(handler); return(config); }
public static RestClientFactoryConfig UseHandler(this RestClientFactoryConfig config, Func <DelegatingHandler> handler) { config.HttpClientBuilder.AddHttpMessageHandler(handler); return(config); }
public static RestClientFactoryConfig UseNoDefaultHandlers(this RestClientFactoryConfig config) { config.UseDefaultHandlers = false; return(config); }
public static RestClientFactoryConfig SetJsonSerializerSettings(this RestClientFactoryConfig config, JsonSerializerSettings jsonSerializerSettings) { config.JsonSerializerSettings = jsonSerializerSettings; return(config); }
public static RestClientFactoryConfig UseCookieHandler(this RestClientFactoryConfig config) { return(UseCookieHandler(config, new CookieContainer())); }