Skip to content
Closed
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
8 changes: 8 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,20 @@
<!-- Set NativeAOT value -->
<_IsNativeAOTFeature Condition="'$(_XamarinRuntime)' == 'NativeAOT'">true</_IsNativeAOTFeature>
<_IsNativeAOTFeature Condition="'$(_XamarinRuntime)' != 'NativeAOT'">false</_IsNativeAOTFeature>

<!-- Computing the values for UseCFNetworkHandler and UseNSUrlSessionHandler -->
<_IsCFNetworkHandlerFeature Condition="'$(UseNativeHttpHandler)' == 'true' And '$(MtouchHttpClientHandler)' == 'CFNetworkHandler'">true</_IsCFNetworkHandlerFeature>
<_IsCFNetworkHandlerFeature Condition="'$(_IsCFNetworkHandlerFeature)' == ''">false</_IsCFNetworkHandlerFeature>
<_IsNSUrlSessionHandlerFeature Condition="'$(UseNativeHttpHandler)' == 'true' And '$(MtouchHttpClientHandler)' == 'NSUrlSessionHandler'">true</_IsNSUrlSessionHandlerFeature>
<_IsNSUrlSessionHandlerFeature Condition="'$(_IsNSUrlSessionHandlerFeature)' == ''">false</_IsNSUrlSessionHandlerFeature>
</PropertyGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="ObjCRuntime.Runtime.Arch.IsSimulator" Value="$(_IsSimulatorFeature)" Trim="true" />
<RuntimeHostConfigurationOption Include="ObjCRuntime.Runtime.IsManagedStaticRegistrar" Value="$(_IsManagedStaticRegistrarFeature)" Trim="true" />
<RuntimeHostConfigurationOption Include="ObjCRuntime.Runtime.IsNativeAOT" Value="$(_IsNativeAOTFeature)" Trim="true" />
<RuntimeHostConfigurationOption Include="ObjCRuntime.Runtime.UseCFNetworkHandler" Value="$(_IsCFNetworkHandlerFeature)" Trim="true" />
<RuntimeHostConfigurationOption Include="ObjCRuntime.Runtime.UseNSUrlSessionHandler" Value="$(_IsNSUrlSessionHandlerFeature)" Trim="true" />
</ItemGroup>
</Target>

Expand Down
6 changes: 6 additions & 0 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public partial class Runtime {
static object lock_obj;
static IntPtr NSObjectClass;
static bool initialized;
static bool useCFNetworkHandler = false;
static bool useNSUrlSessionHandler = false;
Comment on lines +52 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment to the default value is unnecessary, except that the default is to use NSUrlSessionHandler:

Suggested change
static bool useCFNetworkHandler = false;
static bool useNSUrlSessionHandler = false;
static bool useCFNetworkHandler;
static bool useNSUrlSessionHandler = true;


internal static IntPtrEqualityComparer IntPtrEqualityComparer;
internal static TypeEqualityComparer TypeEqualityComparer;
Expand Down Expand Up @@ -249,6 +251,10 @@ public static bool DynamicRegistrationSupported {
}
}

internal static bool UseCFNetworkHandler => useCFNetworkHandler;

internal static bool UseNSUrlSessionHandler => useNSUrlSessionHandler;

internal static bool Initialized {
get { return initialized; }
}
Expand Down
10 changes: 10 additions & 0 deletions src/ObjCRuntime/RuntimeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ internal static TypeDefinition GetHttpMessageHandler (Application app, RuntimeOp

internal static RuntimeOptions? Read ()
{
#if NET
var options = new RuntimeOptions ();
if (Runtime.UseCFNetworkHandler)
options.http_message_handler = CFNetworkHandlerValue;
else if (Runtime.UseNSUrlSessionHandler)
options.http_message_handler = NSUrlSessionHandlerValue;

return options;
#else
Comment on lines 157 to +167
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified a lot more, by inlining this logic in the GetHttpMessageHandler method below:

internal static HttpMessageHandler GetHttpMessageHandler ()
{
#if NET
    if (Runtime.UseCFNetworkHandler)
        return new CFNetworkHandler ();
    if (Runtime.UseNSUrlSessionHandler)
        return new NSUrlSessionHandler ();
    return new HttpClientHandler ();
#else
   // existing logic
#endif
}

// for iOS NSBundle.ResourcePath returns the path to the root of the app bundle
// for macOS apps NSBundle.ResourcePath returns foo.app/Contents/Resources
// for macOS frameworks NSBundle.ResourcePath returns foo.app/Versions/Current/Resources
Expand All @@ -171,6 +180,7 @@ internal static TypeDefinition GetHttpMessageHandler (Application app, RuntimeOp
options.http_message_handler = (NSString) plist ["HttpMessageHandler"];
return options;
}
#endif
}

// This is invoked by
Expand Down