fix SocksWebProxy race condition

This commit is contained in:
kaso17
2017-11-16 16:51:34 +01:00
parent 83ab3c8b07
commit afe64a1b8f

View File

@@ -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,14 +93,9 @@ 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)
{
if (socksWebProxy == null)
{ {
var addresses = await Dns.GetHostAddressesAsync(serverConfig.ProxyUrl); var addresses = await Dns.GetHostAddressesAsync(serverConfig.ProxyUrl);
var socksConfig = new ProxyConfig var socksConfig = new ProxyConfig
@@ -115,10 +111,19 @@ namespace Jackett.Utils.Clients
{ {
socksConfig.SocksPort = serverConfig.ProxyPort.Value; socksConfig.SocksPort = serverConfig.ProxyPort.Value;
} }
proxyServer = new SocksWebProxy(socksConfig, false); socksWebProxy = 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,