Skip to content

Commit

Permalink
core: refactor http webclient part 11 #8529 (#7728)
Browse files Browse the repository at this point in the history
Remove redundant NetCore classes and update client selection logic
  • Loading branch information
cadatoiva authored and ngosang committed Sep 19, 2020
1 parent 3a0ece1 commit e0ef6bc
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 507 deletions.
59 changes: 1 addition & 58 deletions src/Jackett.Common/Plumbing/JackettModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Reflection;
using Autofac;
using Jackett.Common.Indexers;
using Jackett.Common.Indexers.Meta;
Expand Down Expand Up @@ -45,19 +43,14 @@ protected override void Load(ContainerBuilder builder)
switch (_runtimeSettings.ClientOverride)
{
case "httpclientnetcore":
RegisterWebClient<HttpWebClientNetCore>(builder);
break;
case "httpclient2netcore":
RegisterWebClient<HttpWebClient2NetCore>(builder);
break;
case "httpclient":
RegisterWebClient<HttpWebClient>(builder);
break;
case "httpclient2netcore":
case "httpclient2":
RegisterWebClient<HttpWebClient2>(builder);
break;
default:
var usehttpclient = DetectMonoCompatabilityWithHttpClient();
RegisterWebClient<HttpWebClient>(builder);
break;
}
Expand All @@ -70,55 +63,5 @@ private ServerConfig BuildServerConfig(IComponentContext ctx)
var configService = ctx.Resolve<IConfigurationService>();
return configService.BuildServerConfig(_runtimeSettings);
}

private static bool DetectMonoCompatabilityWithHttpClient()
{
var usehttpclient = false;
try
{
var monotype = Type.GetType("Mono.Runtime");
if (monotype != null)
{
var displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName != null)
{
var monoVersion = displayName.Invoke(null, null).ToString();
var monoVersionO = new Version(monoVersion.Split(' ')[0]);
if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5)
{
// check if btls is supported
var monoSecurity = Assembly.Load("Mono.Security");
var monoTlsProviderFactory = monoSecurity.GetType("Mono.Security.Interface.MonoTlsProviderFactory");
if (monoTlsProviderFactory != null)
{
var isProviderSupported = monoTlsProviderFactory.GetMethod("IsProviderSupported");
if (isProviderSupported != null)
{
var btlsSupported = (bool)isProviderSupported.Invoke(null, new string[] { "btls" });
if (btlsSupported)
{
// initialize btls
var initialize = monoTlsProviderFactory.GetMethod("Initialize", new[] { typeof(string) });
if (initialize != null)
{
initialize.Invoke(null, new string[] { "btls" });
usehttpclient = true;
}
}
}
}
}
}
}
}
catch (Exception e)
{
Console.Out.WriteLine("Error while deciding which HttpWebClient to use: " + e);
}

return usehttpclient;
}


}
}
1 change: 0 additions & 1 deletion src/Jackett.Common/Utils/Clients/HttpWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CloudflareSolverRe;
using Jackett.Common.Helpers;
Expand Down
3 changes: 2 additions & 1 deletion src/Jackett.Common/Utils/Clients/HttpWebClient2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CloudflareSolverRe;
using Jackett.Common.Helpers;
Expand Down Expand Up @@ -69,6 +68,8 @@ public override void OnNext(ServerConfig value)

public override void Init()
{
ServicePointManager.DefaultConnectionLimit = 1000;

base.Init();

ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
Expand Down
233 changes: 0 additions & 233 deletions src/Jackett.Common/Utils/Clients/HttpWebClient2NetCore.cs

This file was deleted.

0 comments on commit e0ef6bc

Please sign in to comment.