Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify mobile HttpClientHandler source files #57766

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<PropertyGroup Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsTVOS)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_MOBILE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsAndroid)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_ANDROID</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsiOS)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_IOS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsMacCatalyst)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_MACCATALYST</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsTVOS)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_TVOS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true'">
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
</PropertyGroup>
Expand Down Expand Up @@ -41,10 +53,8 @@
<Compile Include="System\Net\Http\HttpClient.cs" />
<Compile Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsTVOS)' == 'true'"
Include="System\Net\Http\HttpClientHandler.AnyMobile.cs" />
<Compile Condition="'$(TargetsiOS)' == 'true'" Include="System\Net\Http\HttpClientHandler.iOS.cs" />
<Compile Condition="'$(TargetsMacCatalyst)' == 'true'" Include="System\Net\Http\HttpClientHandler.MacCatalyst.cs" />
<Compile Condition="'$(TargetsTVOS)' == 'true'" Include="System\Net\Http\HttpClientHandler.tvOS.cs" />
<Compile Condition="'$(TargetsAndroid)' == 'true'" Include="System\Net\Http\HttpClientHandler.Android.cs" />
<Compile Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsTVOS)' == 'true'"
Include="System\Net\Http\HttpClientHandler.AnyMobile.InvokeNativeHandler.cs" />
<Compile Condition="'$(TargetsAndroid)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetsMacCatalyst)' != 'true' and '$(TargetsTVOS)' != 'true'"
Include="System\Net\Http\HttpClientHandler.cs" />
<Compile Include="System\Net\Http\HttpCompletionOption.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ public partial class HttpClientHandler : HttpMessageHandler
{
private static MethodInfo? _nativeHandlerMethod;

#if TARGET_ANDROID
private const string NativeHandlerType = "Xamarin.Android.Net.AndroidMessageHandler";
private const string AssemblyName = "Mono.Android";
private const string GetHttpMessageHandlerType = "Android.Runtime.AndroidEnvironment, Mono.Android";
#elif TARGET_IOS
private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler";
private const string AssemblyName = "Xamarin.iOS";
private const string GetHttpMessageHandlerType = "ObjCRuntime.RuntimeOptions, Xamarin.iOS";
#elif TARGET_MACCATALYST
private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler";
private const string AssemblyName = "Xamarin.MacCatalyst";
private const string GetHttpMessageHandlerType = "ObjCRuntime.RuntimeOptions, Xamarin.MacCatalyst";
#elif TARGET_TVOS
private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler";
private const string AssemblyName = "Xamarin.TVOS";
private const string GetHttpMessageHandlerType = "ObjCRuntime.RuntimeOptions, Xamarin.TVOS";
#else
#error Unknown target
#endif

[DynamicDependency("get_DefaultProxyCredentials", NativeHandlerType, AssemblyName)]
private ICredentials? GetDefaultProxyCredentials() => (ICredentials?)InvokeNativeHandlerMethod("get_DefaultProxyCredentials");
Expand Down Expand Up @@ -127,7 +144,7 @@ private HttpMessageHandler CreateNativeHandler()
{
if (_nativeHandlerMethod == null)
{
Type? runtimeOptions = Type.GetType("ObjCRuntime.RuntimeOptions, Xamarin.MacCatalyst");
Type? runtimeOptions = Type.GetType(GetHttpMessageHandlerType);
_nativeHandlerMethod = runtimeOptions!.GetMethod("GetHttpMessageHandler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
}

Expand Down
Loading