fix tests with http/2 (dotnet/corefx#36945)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Wed, 17 Apr 2019 04:00:27 +0000 (21:00 -0700)
committerDavid Shulman <david.shulman@microsoft.com>
Wed, 17 Apr 2019 04:00:27 +0000 (21:00 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/f80cf8c360ef00c9a5fdc990e3abd7df23ee0015

src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.cs
src/libraries/System.Net.Http/tests/FunctionalTests/TestHelper.cs

index 922bfd7..f34fdfc 100644 (file)
@@ -56,9 +56,10 @@ namespace System.Net.Http.Functional.Tests
                 Debug.Assert(useSocketsHttpHandler == IsSocketsHttpHandler(handler), "Unexpected handler.");
             }
 
+            TestHelper.EnsureHttp2Feature(handler, useHttp2LoopbackServer);
+
             if (useHttp2LoopbackServer)
             {
-                TestHelper.EnsureHttp2Feature(handler);
                 handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
             }
 
index 42a9abc..bd675de 100644 (file)
@@ -118,7 +118,7 @@ namespace System.Net.Http.Functional.Tests
                 .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
@@ -156,11 +156,14 @@ namespace System.Net.Http.Functional.Tests
                 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()