mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 17:10:20 -10:00
* Make MonoWebRequestHandler linker friendly * Make MonoWebRequestHandler's ctor public (to be able to use in Activator.CreateInstance without binding flags) * Remove Console.WriteLine from system.net.http Co-authored-by: Egor Bogatov <[email protected]>
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 ();
|
|
}
|
|
}
|
|
}
|