1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-05 10:51:15 +00:00

Added Http options to Rest client options

This commit is contained in:
Jkorf
2026-02-24 09:58:48 +01:00
parent b29cdc41f3
commit bea2b2bd7b
3 changed files with 53 additions and 15 deletions
+12 -5
View File
@@ -12,14 +12,16 @@ namespace CryptoExchange.Net.Requests
public class RequestFactory : IRequestFactory
{
private HttpClient? _httpClient;
private RestExchangeOptions? _options;
/// <inheritdoc />
public void Configure(RestExchangeOptions options, HttpClient? client = null)
{
if (client == null)
client = CreateClient(options.Proxy, options.RequestTimeout, options.HttpKeepAliveInterval);
client = CreateClient(options);
_httpClient = client;
_options = options;
}
/// <inheritdoc />
@@ -39,15 +41,20 @@ namespace CryptoExchange.Net.Requests
/// <inheritdoc />
public void UpdateSettings(ApiProxy? proxy, TimeSpan requestTimeout, TimeSpan? httpKeepAliveInterval)
{
_httpClient = CreateClient(proxy, requestTimeout, httpKeepAliveInterval);
var newOptions = new RestExchangeOptions();
_options!.Set(newOptions);
newOptions.Proxy = proxy;
newOptions.RequestTimeout = requestTimeout;
newOptions.HttpKeepAliveInterval = httpKeepAliveInterval;
_httpClient = CreateClient(newOptions);
}
private static HttpClient CreateClient(ApiProxy? proxy, TimeSpan requestTimeout, TimeSpan? httpKeepAliveInterval)
private static HttpClient CreateClient(RestExchangeOptions options)
{
var handler = LibraryHelpers.CreateHttpClientMessageHandler(proxy, httpKeepAliveInterval);
var handler = LibraryHelpers.CreateHttpClientMessageHandler(options);
var client = new HttpClient(handler)
{
Timeout = requestTimeout
Timeout = options.RequestTimeout
};
return client;
}