1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-18 03:43:00 +00:00

added ability to set optional http client for preventing connection pool exhaustion https://stackoverflow.com/a/48778707/4993930

This commit is contained in:
Artem Kurianov
2020-08-18 09:39:14 +00:00
parent 3e3bf5329a
commit 387ef0d1a6
5 changed files with 222 additions and 47 deletions
+21 -14
View File
@@ -11,21 +11,28 @@ namespace CryptoExchange.Net.Requests
/// </summary>
public class RequestFactory : IRequestFactory
{
private HttpClient? httpClient;
private bool isTracingEnabled;
/// <inheritdoc />
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy)
{
HttpMessageHandler handler = new HttpClientHandler()
{
Proxy = proxy == null ? null : new WebProxy
{
Address = new Uri($"{proxy.Host}:{proxy.Port}"),
Credentials = proxy.Password == null ? null : new NetworkCredential(proxy.Login, proxy.Password)
}
};
private HttpClient? httpClient;
httpClient = new HttpClient(handler) { Timeout = requestTimeout };
/// <inheritdoc />
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy, HttpClient? client = null)
{
if (client == null)
{
HttpMessageHandler handler = new HttpClientHandler()
{
Proxy = proxy == null ? null : new WebProxy
{
Address = new Uri($"{proxy.Host}:{proxy.Port}"),
Credentials = proxy.Password == null ? null : new NetworkCredential(proxy.Login, proxy.Password)
}
};
httpClient = new HttpClient(handler) { Timeout = requestTimeout };
}
else
{
httpClient = client;
}
}
/// <inheritdoc />