Debug.Assert(useSocketsHttpHandler == IsSocketsHttpHandler(handler), "Unexpected handler.");
}
+ TestHelper.EnsureHttp2Feature(handler, useHttp2LoopbackServer);
+
if (useHttp2LoopbackServer)
{
- TestHelper.EnsureHttp2Feature(handler);
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
}
.Where(a => a.IsIPv6LinkLocal)
.FirstOrDefault();
- public static void EnsureHttp2Feature(HttpClientHandler handler)
+ public static void EnsureHttp2Feature(HttpClientHandler handler, bool useHttp2LoopbackServer = true)
{
// All .NET Core implementations of HttpClientHandler have HTTP/2 enabled by default except when using
// SocketsHttpHandler. Right now, the HTTP/2 feature is disabled on SocketsHttpHandler unless certain
BindingFlags.NonPublic | BindingFlags.Instance);
field_maxHttpVersion.SetValue(_settings, new Version(2, 0));
- // Allow HTTP/2.0 via unencrypted socket if ALPN is not supported on platform.
- FieldInfo field_allowPlainHttp2 = type_HttpConnectionSettings.GetField(
- "_allowUnencryptedHttp2",
- BindingFlags.NonPublic | BindingFlags.Instance);
- field_allowPlainHttp2.SetValue(_settings, !PlatformDetection.SupportsAlpn);
+ if (useHttp2LoopbackServer && !PlatformDetection.SupportsAlpn)
+ {
+ // Allow HTTP/2.0 via unencrypted socket if ALPN is not supported on platform.
+ FieldInfo field_allowPlainHttp2 = type_HttpConnectionSettings.GetField(
+ "_allowUnencryptedHttp2",
+ BindingFlags.NonPublic | BindingFlags.Instance);
+ field_allowPlainHttp2.SetValue(_settings, !PlatformDetection.SupportsAlpn);
+ }
}
public static bool NativeHandlerSupportsSslConfiguration()