core: Apply declarations styles (#7166)

This commit is contained in:
Cory
2020-02-10 16:16:19 -06:00
committed by GitHub
parent e13cee2e95
commit 348dddfbee
149 changed files with 1039 additions and 1067 deletions

View File

@@ -22,17 +22,17 @@ namespace Jackett.Common.Utils.Clients
// This should improve performance and avoid problems with too man open file handles.
public class HttpWebClient2 : WebClient
{
CookieContainer cookies;
ClearanceHandler clearanceHandlr;
HttpClientHandler clientHandlr;
HttpClient client;
private readonly CookieContainer cookies;
private ClearanceHandler clearanceHandlr;
private HttpClientHandler clientHandlr;
private HttpClient client;
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;
@@ -40,9 +40,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))
@@ -59,7 +58,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)
@@ -152,7 +151,7 @@ namespace Jackett.Common.Utils.Clients
}
}
override public void Init()
public override void Init()
{
if (serverConfig.RuntimeSettings.IgnoreSslErrors == true)
{
@@ -166,7 +165,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)
{
HttpResponseMessage response = null;
var request = new HttpRequestMessage();
@@ -249,7 +248,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();
}
@@ -275,7 +274,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);
}
}
@@ -305,10 +304,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)
{
@@ -331,11 +329,10 @@ namespace Jackett.Common.Utils.Clients
return result;
}
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>();