mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-16 19:03:01 +00:00
3.0 wip
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user