From 5fad5a4d8e29c2da9cfc76449f933ca808ef3ce0 Mon Sep 17 00:00:00 2001 From: Illia Bielkin Date: Sat, 2 Feb 2019 21:55:57 +0200 Subject: [PATCH 1/2] proxy authentication added --- CryptoExchange.Net/Interfaces/IRequest.cs | 2 +- CryptoExchange.Net/Objects/ApiProxy.cs | 27 +++++++++++++++++++++++ CryptoExchange.Net/Requests/Request.cs | 3 ++- CryptoExchange.Net/RestClient.cs | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CryptoExchange.Net/Interfaces/IRequest.cs b/CryptoExchange.Net/Interfaces/IRequest.cs index 6e3b712..457a42d 100644 --- a/CryptoExchange.Net/Interfaces/IRequest.cs +++ b/CryptoExchange.Net/Interfaces/IRequest.cs @@ -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; } diff --git a/CryptoExchange.Net/Objects/ApiProxy.cs b/CryptoExchange.Net/Objects/ApiProxy.cs index 21c7cb6..e9fa865 100644 --- a/CryptoExchange.Net/Objects/ApiProxy.cs +++ b/CryptoExchange.Net/Objects/ApiProxy.cs @@ -13,6 +13,16 @@ namespace CryptoExchange.Net.Objects /// public int Port { get; } + /// + /// The login of the proxy + /// + public string Login { get; } + + /// + /// The password of the proxy + /// + public string Password { get; } + /// /// Create new settings for a proxy /// @@ -26,5 +36,22 @@ namespace CryptoExchange.Net.Objects Host = host; Port = port; } + + /// + /// + /// Create new settings for a proxy + /// + /// The proxy hostname/ip + /// The proxy port + /// The proxy login + /// The proxy password + 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; + } } } diff --git a/CryptoExchange.Net/Requests/Request.cs b/CryptoExchange.Net/Requests/Request.cs index bbdded2..721959b 100644 --- a/CryptoExchange.Net/Requests/Request.cs +++ b/CryptoExchange.Net/Requests/Request.cs @@ -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 GetRequestStream() diff --git a/CryptoExchange.Net/RestClient.cs b/CryptoExchange.Net/RestClient.cs index b82829a..13c79f4 100644 --- a/CryptoExchange.Net/RestClient.cs +++ b/CryptoExchange.Net/RestClient.cs @@ -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) From 85a0fb2fda01640e32e711822773fc091c887a14 Mon Sep 17 00:00:00 2001 From: Illia Bielkin Date: Sun, 3 Feb 2019 10:58:15 +0200 Subject: [PATCH 2/2] constructor fixed --- CryptoExchange.Net/Objects/ApiProxy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Objects/ApiProxy.cs b/CryptoExchange.Net/Objects/ApiProxy.cs index e9fa865..970f5b6 100644 --- a/CryptoExchange.Net/Objects/ApiProxy.cs +++ b/CryptoExchange.Net/Objects/ApiProxy.cs @@ -51,7 +51,7 @@ namespace CryptoExchange.Net.Objects throw new ArgumentException("Proxy login or password not filled"); Login = login; - Password = Password; + Password = password; } } }