Skip to content

Commit d2c991e

Browse files
[Android][iOS] Enable HttpClientHandler.DangerousAcceptAnyServerCertificateValidator when using native handlers (#73763)
The static `HttpClientHandler.DangerousAcceptAnyServerCertificateValidator` getter throws PNSE when the native HTTP handler is enabled because Xamarin.Android's `AndroidMessageHandler` and Xamarin.iOS `NSUrlSessionHandler` didn't use to have support for the `ServerCertificateCustomValidationCallback`. We already implemented the Android part in .NET 6 and support in the iOS implementation is WIP and we should be able to implement it in time for .NET 7. IMO it's safe to remove the exception in the getter in .NET 7. Closes #68898
1 parent 14be2a0 commit d2c991e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -738,16 +738,9 @@ protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessa
738738
{
739739
get
740740
{
741-
if (IsNativeHandlerEnabled)
742-
{
743-
throw new PlatformNotSupportedException();
744-
}
745-
else
746-
{
747-
return Volatile.Read(ref s_dangerousAcceptAnyServerCertificateValidator) ??
748-
Interlocked.CompareExchange(ref s_dangerousAcceptAnyServerCertificateValidator, delegate { return true; }, null) ??
749-
s_dangerousAcceptAnyServerCertificateValidator;
750-
}
741+
return Volatile.Read(ref s_dangerousAcceptAnyServerCertificateValidator) ??
742+
Interlocked.CompareExchange(ref s_dangerousAcceptAnyServerCertificateValidator, delegate { return true; }, null) ??
743+
s_dangerousAcceptAnyServerCertificateValidator;
751744
}
752745
}
753746

0 commit comments

Comments
 (0)