diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 8f495ebd79224..841bae61b9ecf 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -6,7 +6,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Android enable - + $(DefineConstants);SYSNETHTTP_NO_OPENSSL @@ -36,9 +36,10 @@ - + + diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.CreateDefaultHandler.MacCatalyst.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.CreateDefaultHandler.MacCatalyst.cs new file mode 100644 index 0000000000000..dc19e0ed35d87 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.CreateDefaultHandler.MacCatalyst.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; + +namespace System.Net.Http +{ + public partial class HttpClient + { + private static MethodInfo? handlerMethod; + + private static HttpMessageHandler CreateDefaultHandler() + { + // Default is to use the iOS native handler + if (!IsNativeHandlerEnabled()) + { + return new HttpClientHandler(); + } + + if (handlerMethod == null) + { + Type? runtimeOptions = Type.GetType("ObjCRuntime.RuntimeOptions, Xamarin.MacCatalyst"); + handlerMethod = runtimeOptions!.GetMethod("GetHttpMessageHandler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); + } + + return (HttpMessageHandler)handlerMethod!.Invoke(null, null)!; + } + } +}