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:
@@ -21,19 +21,18 @@ namespace Jackett.Common.Utils.Clients
|
||||
// custom HttpWebClient based WebClient for netcore (due to changed custom certificate validation API)
|
||||
public class HttpWebClientNetCore : 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(HttpRequestMessage request, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
public static bool ValidateCertificate(HttpRequestMessage request, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
{
|
||||
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.RequestUri.Host))
|
||||
@@ -51,7 +50,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
}
|
||||
}
|
||||
|
||||
static public void InitProxy(ServerConfig serverConfig)
|
||||
public static void InitProxy(ServerConfig serverConfig)
|
||||
{
|
||||
// dispose old SocksWebProxy
|
||||
if (webProxy != null && webProxy is SocksWebProxy)
|
||||
@@ -117,7 +116,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
InitProxy(serverConfig);
|
||||
}
|
||||
|
||||
override public void Init()
|
||||
public override void Init()
|
||||
{
|
||||
ServicePointManager.DefaultConnectionLimit = 1000;
|
||||
|
||||
@@ -128,7 +127,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
}
|
||||
}
|
||||
|
||||
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||
{
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
||||
|
||||
@@ -150,12 +149,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.
|
||||
@@ -230,7 +229,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();
|
||||
}
|
||||
|
||||
@@ -256,7 +255,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);
|
||||
}
|
||||
}
|
||||
@@ -286,10 +285,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)
|
||||
{
|
||||
@@ -316,11 +314,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