1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-07 16:06:15 +00:00

Update SetProxy

This commit is contained in:
Mohammad Reza 2022-04-13 17:37:48 +04:30
parent 4f4d2ccff3
commit c4f4ddcdc5
2 changed files with 7 additions and 29 deletions

View File

@ -1,12 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
@ -492,23 +490,6 @@ namespace CryptoExchange.Net
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);
}
}
}

View File

@ -212,18 +212,15 @@ namespace CryptoExchange.Net.Sockets
/// <inheritdoc />
public virtual void SetProxy(ApiProxy proxy)
{
if (!proxy.IsSchemaProvided())
{
_socket.Options.Proxy = new WebProxy(proxy.Host, proxy.Port);
}
else
{
_socket.Options.Proxy = new WebProxy
Uri.TryCreate($"{proxy.Host}:{proxy.Port}", UriKind.Absolute, out var uri);
_socket.Options.Proxy = uri?.Scheme == null
? _socket.Options.Proxy = new WebProxy(proxy.Host, proxy.Port)
: _socket.Options.Proxy = new WebProxy
{
Address = new Uri($"{proxy.Host}:{proxy.Port}"),
Credentials = proxy.Password == null ? null : new NetworkCredential(proxy.Login, proxy.Password)
Address = uri
};
}
if (proxy.Login != null)
_socket.Options.Proxy.Credentials = new NetworkCredential(proxy.Login, proxy.Password);
}
/// <inheritdoc />