You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Include native underlying handler support in HttpClientHandler for iOS/tvOS/MacCatalyst and Android (#55384)
Completes the plan for net6 laid out in https://github.com/dotnet/designs/blob/main/accepted/2020/mono-convergence/platform-specific-httpclient.md#the-plan-for-net-5
This change supports using either the native HttpMessageHandler types that exist in the Xamarin repos (NSUrlSessionHandler for iOS/tvOS/Catalyst and AndroidMessageHandler for Android) or SocketsHttpHandler as the underlying handler in HttpClientHandler.
The behavior for new HttpClient() was established earlier in net6, but did not go all the way. For example, if the System.Net.Http.UseNativeHttpHandler feature switch was set to true, using HttpClient in different ways would lead to different underlying handlers.
Before this PR:
// System.Net.Http.UseNativeHttpHandler == true
new HttpClient(); // Chooses the native handler as the underlying handler
var handler = new HttpClientHandler(); // SocketsHttpHandler is the only choice
new HttpClient(handler);
The change creates a handful of partial HttpClientHandler files in order to split out the platform specific parts. As you review the PR, you'll notice a bunch of if (IsSocketHandler) blocks. The intent of these are to make use of the linker and get linked out once the linker knows which handler is the active one.
get
{
if (IsSocketHandler)
{
return _socketHandler!.UseCookies;
}
else
{
return GetUseCookies();
}
}
Get and Set methods like GetUseCookies make it easier to tell the linker via DynamicDependency to preserve the reflection calls being made to the native underlying handler.
[DynamicDependency("get_UseCookies", "Xamarin.Android.Net.AndroidMessageHandler", "Mono.Android")]
private bool GetUseCookies() => (bool)InvokeNativeHandlerMethod("get_UseCookies");
It is important to point out that the underlying handler has to be derived from HttpMessageHandler. It cannot be HttpClientHandler or you'll end up with a circular dependency.
0 commit comments