1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 08:56:13 +00:00

proxy authentication added

This commit is contained in:
Illia Bielkin 2019-02-02 21:55:57 +02:00
parent a56de43ca3
commit 5fad5a4d8e
4 changed files with 31 additions and 3 deletions

View File

@ -11,7 +11,7 @@ namespace CryptoExchange.Net.Interfaces
WebHeaderCollection Headers { get; set; }
string Method { get; set; }
TimeSpan Timeout { get; set; }
void SetProxy(string host, int port);
void SetProxy(string host, int port, string login, string password);
string ContentType { get; set; }
string Content { get; set; }

View File

@ -13,6 +13,16 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public int Port { get; }
/// <summary>
/// The login of the proxy
/// </summary>
public string Login { get; }
/// <summary>
/// The password of the proxy
/// </summary>
public string Password { get; }
/// <summary>
/// Create new settings for a proxy
/// </summary>
@ -26,5 +36,22 @@ namespace CryptoExchange.Net.Objects
Host = host;
Port = port;
}
/// <inheritdoc />
/// <summary>
/// Create new settings for a proxy
/// </summary>
/// <param name="host">The proxy hostname/ip</param>
/// <param name="port">The proxy port</param>
/// <param name="login">The proxy login</param>
/// <param name="password">The proxy password</param>
public ApiProxy(string host, int port, string login, string password) : this(host, port)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
throw new ArgumentException("Proxy login or password not filled");
Login = login;
Password = Password;
}
}
}

View File

@ -54,9 +54,10 @@ namespace CryptoExchange.Net.Requests
public Uri Uri => request.RequestUri;
public void SetProxy(string host, int port)
public void SetProxy(string host, int port, string login, string password)
{
request.Proxy = new WebProxy(host, port);
if(!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(password)) request.Proxy.Credentials = new NetworkCredential(login, password);
}
public async Task<Stream> GetRequestStream()

View File

@ -129,7 +129,7 @@ namespace CryptoExchange.Net
if (apiProxy != null)
{
log.Write(LogVerbosity.Debug, "Setting proxy");
request.SetProxy(apiProxy.Host, apiProxy.Port);
request.SetProxy(apiProxy.Host, apiProxy.Port, apiProxy.Login, apiProxy.Password);
}
foreach (var limiter in RateLimiters)