mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
add Schema check
This commit is contained in:
parent
4db43517b7
commit
4f4d2ccff3
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using CryptoExchange.Net.Logging;
|
using CryptoExchange.Net.Logging;
|
||||||
using CryptoExchange.Net.Objects;
|
using CryptoExchange.Net.Objects;
|
||||||
@ -492,6 +493,22 @@ namespace CryptoExchange.Net
|
|||||||
return ub.Uri;
|
return ub.Uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// checks whether schema is provided
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="proxy"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsSchemaProvided(this ApiProxy proxy)
|
||||||
|
{
|
||||||
|
var url = $"{proxy.Host}:{proxy.Port}";
|
||||||
|
var r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?",
|
||||||
|
RegexOptions.None, TimeSpan.FromMilliseconds(150));
|
||||||
|
var match = r.Match(url);
|
||||||
|
if (!match.Success) return false;
|
||||||
|
var proto = match.Result("${proto}");
|
||||||
|
return !string.IsNullOrEmpty(proto);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,13 +212,19 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void SetProxy(ApiProxy proxy)
|
public virtual void SetProxy(ApiProxy proxy)
|
||||||
{
|
{
|
||||||
|
if (!proxy.IsSchemaProvided())
|
||||||
|
{
|
||||||
|
_socket.Options.Proxy = new WebProxy(proxy.Host, proxy.Port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_socket.Options.Proxy = new WebProxy
|
_socket.Options.Proxy = new WebProxy
|
||||||
{
|
{
|
||||||
Address = new Uri($"{proxy.Host}:{proxy.Port}"),
|
Address = new Uri($"{proxy.Host}:{proxy.Port}"),
|
||||||
Credentials = proxy.Password == null ? null : new NetworkCredential(proxy.Login, proxy.Password)
|
Credentials = proxy.Password == null ? null : new NetworkCredential(proxy.Login, proxy.Password)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual async Task<bool> ConnectAsync()
|
public virtual async Task<bool> ConnectAsync()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user