mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -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
28 lines
1013 B
C#
28 lines
1013 B
C#
using System.Reflection;
|
|
|
|
namespace System.Net.Http
|
|
{
|
|
partial class HttpClientHandler : HttpMessageHandler
|
|
{
|
|
static IMonoHttpClientHandler CreateDefaultHandler ()
|
|
{
|
|
string envvar = Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE")?.Trim ();
|
|
if (envvar?.StartsWith("System.Net.Http.MonoWebRequestHandler", StringComparison.InvariantCulture) == true)
|
|
{
|
|
Type monoWrhType = Type.GetType (envvar, false);
|
|
if (monoWrhType != null)
|
|
return (IMonoHttpClientHandler) Activator.CreateInstance (monoWrhType);
|
|
}
|
|
|
|
// Ignore other types of handlers here (e.g. AndroidHttpHandler) to keep the old behavior
|
|
// and always create SocketsHttpHandler for code like this if MonoWebRequestHandler was not specified:
|
|
//
|
|
// var handler = new HttpClientHandler { Credentials = ... };
|
|
// var httpClient = new HttpClient (handler);
|
|
//
|
|
// AndroidHttpHandler is used only when we use the parameterless ctor of HttpClient
|
|
return new SocketsHttpHandler ();
|
|
}
|
|
}
|
|
}
|