1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-16 19:03:01 +00:00
This commit is contained in:
Jan Korf
2019-10-11 14:48:30 +02:00
parent 715fe378d5
commit 8ec902951d
33 changed files with 725 additions and 655 deletions
+27 -3
View File
@@ -1,5 +1,8 @@
using System.Net;
using System;
using System.Net;
using System.Net.Http;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
namespace CryptoExchange.Net.Requests
{
@@ -8,10 +11,31 @@ namespace CryptoExchange.Net.Requests
/// </summary>
public class RequestFactory : IRequestFactory
{
private HttpClient? httpClient;
/// <inheritdoc />
public IRequest Create(string uri)
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy)
{
return new Request(WebRequest.Create(uri));
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);
httpClient.Timeout = requestTimeout;
}
/// <inheritdoc />
public IRequest Create(HttpMethod method, string uri)
{
if (httpClient == null)
throw new InvalidOperationException("Cant create request before configuring http client");
return new Request(new HttpRequestMessage(method, uri), httpClient);
}
}
}