mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
fix SocksWebProxy race condition
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Jackett.Utils.Clients
|
|||||||
public class HttpWebClient : WebClient
|
public class HttpWebClient : WebClient
|
||||||
{
|
{
|
||||||
static protected Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
static protected Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
||||||
|
static protected SocksWebProxy socksWebProxy;
|
||||||
|
|
||||||
public HttpWebClient(IProcessService p, Logger l, IConfigurationService c, ServerConfig sc)
|
public HttpWebClient(IProcessService p, Logger l, IConfigurationService c, ServerConfig sc)
|
||||||
: base(p: p,
|
: base(p: p,
|
||||||
@@ -92,33 +93,37 @@ namespace Jackett.Utils.Clients
|
|||||||
if (!string.IsNullOrWhiteSpace(proxyUrl))
|
if (!string.IsNullOrWhiteSpace(proxyUrl))
|
||||||
{
|
{
|
||||||
useProxy = true;
|
useProxy = true;
|
||||||
NetworkCredential creds = null;
|
|
||||||
if (!serverConfig.ProxyIsAnonymous)
|
|
||||||
{
|
|
||||||
var username = serverConfig.ProxyUsername;
|
|
||||||
var password = serverConfig.ProxyPassword;
|
|
||||||
creds = new NetworkCredential(username, password);
|
|
||||||
}
|
|
||||||
if (serverConfig.ProxyType != ProxyType.Http)
|
if (serverConfig.ProxyType != ProxyType.Http)
|
||||||
{
|
{
|
||||||
var addresses = await Dns.GetHostAddressesAsync(serverConfig.ProxyUrl);
|
if (socksWebProxy == null)
|
||||||
var socksConfig = new ProxyConfig
|
|
||||||
{
|
{
|
||||||
SocksAddress = addresses.FirstOrDefault(),
|
var addresses = await Dns.GetHostAddressesAsync(serverConfig.ProxyUrl);
|
||||||
Username = serverConfig.ProxyUsername,
|
var socksConfig = new ProxyConfig
|
||||||
Password = serverConfig.ProxyPassword,
|
{
|
||||||
Version = serverConfig.ProxyType == ProxyType.Socks4 ?
|
SocksAddress = addresses.FirstOrDefault(),
|
||||||
ProxyConfig.SocksVersion.Four :
|
Username = serverConfig.ProxyUsername,
|
||||||
ProxyConfig.SocksVersion.Five
|
Password = serverConfig.ProxyPassword,
|
||||||
};
|
Version = serverConfig.ProxyType == ProxyType.Socks4 ?
|
||||||
if (serverConfig.ProxyPort.HasValue)
|
ProxyConfig.SocksVersion.Four :
|
||||||
{
|
ProxyConfig.SocksVersion.Five
|
||||||
socksConfig.SocksPort = serverConfig.ProxyPort.Value;
|
};
|
||||||
|
if (serverConfig.ProxyPort.HasValue)
|
||||||
|
{
|
||||||
|
socksConfig.SocksPort = serverConfig.ProxyPort.Value;
|
||||||
|
}
|
||||||
|
socksWebProxy = new SocksWebProxy(socksConfig, false);
|
||||||
}
|
}
|
||||||
proxyServer = new SocksWebProxy(socksConfig, false);
|
proxyServer = socksWebProxy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
NetworkCredential creds = null;
|
||||||
|
if (!serverConfig.ProxyIsAnonymous)
|
||||||
|
{
|
||||||
|
var username = serverConfig.ProxyUsername;
|
||||||
|
var password = serverConfig.ProxyPassword;
|
||||||
|
creds = new NetworkCredential(username, password);
|
||||||
|
}
|
||||||
proxyServer = new WebProxy(proxyUrl)
|
proxyServer = new WebProxy(proxyUrl)
|
||||||
{
|
{
|
||||||
BypassProxyOnLocal = false,
|
BypassProxyOnLocal = false,
|
||||||
|
Reference in New Issue
Block a user