mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
core: Apply declarations styles (#7166)
This commit is contained in:
@@ -20,12 +20,12 @@ namespace Jackett.Common.Utils.Clients
|
||||
{
|
||||
public class HttpWebClient : WebClient
|
||||
{
|
||||
static protected Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
||||
static protected string webProxyUrl;
|
||||
static protected IWebProxy webProxy;
|
||||
protected static Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
||||
protected static string webProxyUrl;
|
||||
protected static IWebProxy webProxy;
|
||||
|
||||
[DebuggerNonUserCode] // avoid "Exception User-Unhandled" Visual Studio messages
|
||||
static public bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
public static bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
if (sender.GetType() != typeof(HttpWebRequest))
|
||||
return sslPolicyErrors == SslPolicyErrors.None;
|
||||
@@ -33,9 +33,8 @@ namespace Jackett.Common.Utils.Clients
|
||||
var request = (HttpWebRequest)sender;
|
||||
var hash = certificate.GetCertHashString();
|
||||
|
||||
ICollection<string> hosts;
|
||||
|
||||
trustedCertificates.TryGetValue(hash, out hosts);
|
||||
trustedCertificates.TryGetValue(hash, out var hosts);
|
||||
if (hosts != null)
|
||||
{
|
||||
if (hosts.Contains(request.Host))
|
||||
@@ -52,7 +51,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
return sslPolicyErrors == SslPolicyErrors.None;
|
||||
}
|
||||
|
||||
static public void InitProxy(ServerConfig serverConfig)
|
||||
public static void InitProxy(ServerConfig serverConfig)
|
||||
{
|
||||
// dispose old SocksWebProxy
|
||||
if (webProxy != null && webProxy is SocksWebProxy)
|
||||
@@ -118,7 +117,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
InitProxy(serverConfig);
|
||||
}
|
||||
|
||||
override public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
ServicePointManager.DefaultConnectionLimit = 1000;
|
||||
|
||||
@@ -132,7 +131,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;
|
||||
}
|
||||
|
||||
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||
{
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
||||
|
||||
@@ -154,12 +153,12 @@ namespace Jackett.Common.Utils.Clients
|
||||
}
|
||||
}
|
||||
|
||||
string userAgent = webRequest.EmulateBrowser.Value ? BrowserUtil.ChromeUserAgent : "Jackett/" + configService.GetVersion();
|
||||
var userAgent = webRequest.EmulateBrowser.Value ? BrowserUtil.ChromeUserAgent : "Jackett/" + configService.GetVersion();
|
||||
|
||||
using (ClearanceHandler clearanceHandlr = new ClearanceHandler(userAgent))
|
||||
using (var clearanceHandlr = new ClearanceHandler(userAgent))
|
||||
{
|
||||
clearanceHandlr.MaxTries = 30;
|
||||
using (HttpClientHandler clientHandlr = new HttpClientHandler
|
||||
using (var clientHandlr = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = false, // Do not use this - Bugs ahoy! Lost cookies and more.
|
||||
@@ -231,7 +230,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
|
||||
foreach (var header in response.Headers)
|
||||
{
|
||||
IEnumerable<string> value = header.Value;
|
||||
var value = header.Value;
|
||||
result.Headers[header.Key.ToLowerInvariant()] = value.ToArray();
|
||||
}
|
||||
|
||||
@@ -257,7 +256,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
// of this cloudflare approach..don't want to alter BaseWebResult.IsRedirect because normally
|
||||
// it shoudln't include service unavailable..only if we have this redirect header.
|
||||
response.StatusCode = System.Net.HttpStatusCode.Redirect;
|
||||
redirtime = Int32.Parse(value.Substring(0, end));
|
||||
redirtime = int.Parse(value.Substring(0, end));
|
||||
System.Threading.Thread.Sleep(redirtime * 1000);
|
||||
}
|
||||
}
|
||||
@@ -287,10 +286,9 @@ namespace Jackett.Common.Utils.Clients
|
||||
// Compatiblity issue between the cookie format and httpclient
|
||||
// Pull it out manually ignoring the expiry date then set it manually
|
||||
// http://stackoverflow.com/questions/14681144/httpclient-not-storing-cookies-in-cookiecontainer
|
||||
IEnumerable<string> cookieHeaders;
|
||||
var responseCookies = new List<Tuple<string, string>>();
|
||||
|
||||
if (response.Headers.TryGetValues("set-cookie", out cookieHeaders))
|
||||
if (response.Headers.TryGetValues("set-cookie", out var cookieHeaders))
|
||||
{
|
||||
foreach (var value in cookieHeaders)
|
||||
{
|
||||
@@ -317,11 +315,10 @@ namespace Jackett.Common.Utils.Clients
|
||||
}
|
||||
}
|
||||
|
||||
override public void AddTrustedCertificate(string host, string hash)
|
||||
public override void AddTrustedCertificate(string host, string hash)
|
||||
{
|
||||
hash = hash.ToUpper();
|
||||
ICollection<string> hosts;
|
||||
trustedCertificates.TryGetValue(hash.ToUpper(), out hosts);
|
||||
trustedCertificates.TryGetValue(hash.ToUpper(), out var hosts);
|
||||
if (hosts == null)
|
||||
{
|
||||
hosts = new HashSet<string>();
|
||||
|
Reference in New Issue
Block a user