mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
Create it using reflection so it will be always linked out. However if it's set via `XA_HTTP_CLIENT_HANDLER_TYPE` linker will preserve it in a special substep: https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/PreserveHttpAndroidClientHandler.cs#L72-L80 I had to make its ctor **public** because Linker instantiate it via `Activator.CreateInstance(string)` ([here](https://github.com/xamarin/xamarin-android/blob/60363ef45cd6994a322adac1b73d4271b0658c1e/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs#L369)). But the whole type remains internal so it's not a real API change. Fixes issue from https://github.com/mono/mono/pull/18818#issuecomment-585611647
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace System.Net.Http {
|
|
public partial class HttpClient {
|
|
|
|
static HttpMessageHandler CreateDefaultHandler ()
|
|
{
|
|
string envvar = Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE")?.Trim ();
|
|
|
|
if (string.IsNullOrEmpty (envvar))
|
|
return new HttpClientHandler ();
|
|
|
|
if (envvar?.StartsWith ("System.Net.Http.MonoWebRequestHandler", StringComparison.InvariantCulture) == true)
|
|
{
|
|
Type monoWrhType = Type.GetType (envvar, false);
|
|
if (monoWrhType != null)
|
|
return new HttpClientHandler ((IMonoHttpClientHandler) Activator.CreateInstance (monoWrhType));
|
|
|
|
return new HttpClientHandler ();
|
|
}
|
|
|
|
Type handlerType = Type.GetType (envvar, false);
|
|
if (handlerType == null && !envvar.Contains (", "))
|
|
{
|
|
// if assembly was not specified - look for it in Mono.Android too
|
|
// (e.g. AndroidHttpHandler is there)
|
|
handlerType = Type.GetType (envvar + ", Mono.Android", false);
|
|
}
|
|
|
|
if (handlerType == null)
|
|
return new HttpClientHandler ();
|
|
|
|
if (Activator.CreateInstance (handlerType) is HttpMessageHandler msgHandler)
|
|
return msgHandler;
|
|
|
|
return new HttpClientHandler ();
|
|
}
|
|
}
|
|
}
|