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

Merge pull request #135 from mohammadj22/ImproveWebSocketClientProxy

change SetProxy method in web socket client to support socks5 proxy.
This commit is contained in:
Jan Korf 2022-04-14 15:05:19 +02:00 committed by GitHub
commit 13c81afb79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -491,7 +490,6 @@ namespace CryptoExchange.Net
return ub.Uri; return ub.Uri;
} }
} }
} }

View File

@ -212,7 +212,13 @@ namespace CryptoExchange.Net.Sockets
/// <inheritdoc /> /// <inheritdoc />
public virtual void SetProxy(ApiProxy proxy) public virtual void SetProxy(ApiProxy proxy)
{ {
_socket.Options.Proxy = new WebProxy(proxy.Host, proxy.Port); 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 = uri
};
if (proxy.Login != null) if (proxy.Login != null)
_socket.Options.Proxy.Credentials = new NetworkCredential(proxy.Login, proxy.Password); _socket.Options.Proxy.Credentials = new NetworkCredential(proxy.Login, proxy.Password);
} }