Skip to content

Commit

Permalink
Ensure MacCatalyst default http handler is the same as iOS (#52229)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveisok authored May 11, 2021
1 parent eb54d0d commit 90f2cef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Android</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetsOSX)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
<PropertyGroup Condition=" '$(TargetsOSX)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true'">
<DefineConstants>$(DefineConstants);SYSNETHTTP_NO_OPENSSL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true'">
Expand Down Expand Up @@ -36,9 +36,10 @@
<Compile Include="System\Net\Http\Headers\KnownHeaders.cs" />
<Compile Include="System\Net\Http\HttpBaseStream.cs" />
<Compile Include="System\Net\Http\HttpClient.cs" />
<Compile Condition="'$(TargetsAndroid)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetsTVOS)' != 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.cs" />
<Compile Condition="'$(TargetsAndroid)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetsMacCatalyst)' != 'true' and '$(TargetsTVOS)' != 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.cs" />
<Compile Condition="'$(TargetsAndroid)' == 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.Android.cs" />
<Compile Condition="'$(TargetsiOS)' == 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.iOS.cs" />
<Compile Condition="'$(TargetsMacCatalyst)' == 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.MacCatalyst.cs" />
<Compile Condition="'$(TargetsTVOS)' == 'true'" Include="System\Net\Http\HttpClient.CreateDefaultHandler.tvOS.cs" />
<Compile Include="System\Net\Http\HttpClientHandler.cs" />
<Compile Include="System\Net\Http\HttpCompletionOption.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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)!;
}
}
}

0 comments on commit 90f2cef

Please sign in to comment.