From d5facbbc492c312200a5fe3ed6abf2e57c191150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marie=20P=C3=ADchov=C3=A1?= Date: Thu, 8 Jul 2021 14:12:24 +0200 Subject: [PATCH 1/3] Renamed AllowDraftHttp3 to AllowHttp3AndQuic app context switch --- .../src/System/Net/Http/GlobalHttpSettings.cs | 12 ++++++------ .../SocketsHttpHandler/HttpConnectionSettings.cs | 2 +- .../System.Net.Http.Functional.Tests.csproj | 4 ++++ .../tests/StressTests/HttpStress/HttpStress.csproj | 4 ++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs b/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs index 7382f4ca0da13c..6be78202df9d95 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs @@ -26,12 +26,12 @@ internal static class SocketsHttpHandler "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2SUPPORT", true); - // Default to allowing draft HTTP/3, but enable that to be overridden - // by an AppContext switch, or by an environment variable being set to false/0. - public static bool AllowDraftHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( - "System.Net.SocketsHttpHandler.Http3DraftSupport", - "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3DRAFTSUPPORT", - true); + // Default to disable HTTP/3 and QUIC, but enable that to be overridden + // by an AppContext switch, or by an environment variable being set to true/1. + public static bool AllowHttp3AndQuic { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( + "System.Net.SocketsHttpHandler.Http3AndQuicSupport", + "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3ANDQUICSUPPORT", + false); // Switch to disable the HTTP/2 dynamic window scaling algorithm. Enabled by default. public static bool DisableDynamicHttp2WindowSizing { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs index 03cb3e9a406243..6fe21080de34b1 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs @@ -67,7 +67,7 @@ internal sealed class HttpConnectionSettings public HttpConnectionSettings() { bool allowHttp2 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp2; - bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowDraftHttp3; + bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp3AndQuic; _maxHttpVersion = allowHttp3 && allowHttp2 ? HttpVersion.Version30 : allowHttp2 ? HttpVersion.Version20 : diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index b3413cbef30533..7b65da0e52c6a0 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -9,6 +9,10 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX + + + + WasmTestOnBrowser $(TestArchiveRoot)browseronly/ diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj index 57cbb0859dc804..c7836be1767d10 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj @@ -7,6 +7,10 @@ enable + + + + From e5fbe81acfa5c3c3594229001deb82aff9a3faab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marie=20P=C3=ADchov=C3=A1?= Date: Thu, 8 Jul 2021 15:08:00 +0200 Subject: [PATCH 2/3] Usage of AllowHttp3AndQuic switch in S.N.Quic and enabling it in tests --- .../MsQuic/Internal/MsQuicApi.cs | 40 ++++++++++++++++++- .../System.Net.Quic.Functional.Tests.csproj | 3 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs index 2bf1b9b1955e81..27c35d0c5b5511 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs @@ -125,10 +125,18 @@ private MsQuicApi(NativeApi* vtable) static MsQuicApi() { - if (OperatingSystem.IsWindows() && !IsWindowsVersionSupported()) + if (!IsHttp3AndQuicEnabled()) { - IsQuicSupported = false; + if (NetEventSource.Log.IsEnabled()) + { + NetEventSource.Info(null, $"HTTP/3 and QUIC is not enabled, see 'System.Net.SocketsHttpHandler.Http3AndQuicSupport' AppContext switch."); + } + return; + } + + if (OperatingSystem.IsWindows() && !IsWindowsVersionSupported()) + { if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(null, $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {MinWindowsVersion}"); @@ -163,6 +171,34 @@ static MsQuicApi() } } + // Note that this is copy-pasted from S.N.Http just to hide S.N.Quic behind the same AppContext switch + // since this library is considered "private" for 6.0. + // We should get rid of this once S.N.Quic API surface is officially exposed. + private static bool IsHttp3AndQuicEnabled() + { + bool value; + + // First check for the AppContext switch, giving it priority over the environment variable. + if (AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3AndQuicSupport", out value)) + { + return value; + } + + // AppContext switch wasn't used. Check the environment variable. + string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3ANDQUICSUPPORT"); + + if (bool.TryParse(envVar, out value)) + { + return value; + } + else if (uint.TryParse(envVar, out uint intVal)) + { + return intVal != 0; + } + + return false; + } + private static bool IsWindowsVersionSupported() => OperatingSystem.IsWindowsVersionAtLeast(MinWindowsVersion.Major, MinWindowsVersion.Minor, MinWindowsVersion.Build, MinWindowsVersion.Revision); diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj index 2a17894a5555a7..2d2f2cc137de2c 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj @@ -4,6 +4,9 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix + + + From c9f0a8c26560ad397068884478a956547b913198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marie=20P=C3=ADchov=C3=A1?= Date: Tue, 13 Jul 2021 19:40:42 +0200 Subject: [PATCH 3/3] Renamed AppContext switch to Http3Support --- .../src/System/Net/Http/GlobalHttpSettings.cs | 8 ++++---- .../Http/SocketsHttpHandler/HttpConnectionSettings.cs | 2 +- .../System.Net.Http.Functional.Tests.csproj | 2 +- .../tests/StressTests/HttpStress/HttpStress.csproj | 2 +- .../Quic/Implementations/MsQuic/Internal/MsQuicApi.cs | 10 +++++----- .../System.Net.Quic.Functional.Tests.csproj | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs b/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs index 6be78202df9d95..664d296dcb6d19 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs @@ -26,11 +26,11 @@ internal static class SocketsHttpHandler "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2SUPPORT", true); - // Default to disable HTTP/3 and QUIC, but enable that to be overridden + // Default to disable HTTP/3 (and by an extent QUIC), but enable that to be overridden // by an AppContext switch, or by an environment variable being set to true/1. - public static bool AllowHttp3AndQuic { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( - "System.Net.SocketsHttpHandler.Http3AndQuicSupport", - "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3ANDQUICSUPPORT", + public static bool AllowHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( + "System.Net.SocketsHttpHandler.Http3Support", + "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT", false); // Switch to disable the HTTP/2 dynamic window scaling algorithm. Enabled by default. diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs index 6fe21080de34b1..193202756025a4 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs @@ -67,7 +67,7 @@ internal sealed class HttpConnectionSettings public HttpConnectionSettings() { bool allowHttp2 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp2; - bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp3AndQuic; + bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp3; _maxHttpVersion = allowHttp3 && allowHttp2 ? HttpVersion.Version30 : allowHttp2 ? HttpVersion.Version20 : diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 7b65da0e52c6a0..667b35e9a8afeb 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj index c7836be1767d10..b133d630a48063 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs index 27c35d0c5b5511..ea09d3bf6add51 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs @@ -125,11 +125,11 @@ private MsQuicApi(NativeApi* vtable) static MsQuicApi() { - if (!IsHttp3AndQuicEnabled()) + if (!IsHttp3Enabled()) { if (NetEventSource.Log.IsEnabled()) { - NetEventSource.Info(null, $"HTTP/3 and QUIC is not enabled, see 'System.Net.SocketsHttpHandler.Http3AndQuicSupport' AppContext switch."); + NetEventSource.Info(null, $"HTTP/3 and QUIC is not enabled, see 'System.Net.SocketsHttpHandler.Http3Support' AppContext switch."); } return; @@ -174,18 +174,18 @@ static MsQuicApi() // Note that this is copy-pasted from S.N.Http just to hide S.N.Quic behind the same AppContext switch // since this library is considered "private" for 6.0. // We should get rid of this once S.N.Quic API surface is officially exposed. - private static bool IsHttp3AndQuicEnabled() + private static bool IsHttp3Enabled() { bool value; // First check for the AppContext switch, giving it priority over the environment variable. - if (AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3AndQuicSupport", out value)) + if (AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3Support", out value)) { return value; } // AppContext switch wasn't used. Check the environment variable. - string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3ANDQUICSUPPORT"); + string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT"); if (bool.TryParse(envVar, out value)) { diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj index 2d2f2cc137de2c..583b2b6c4861ee 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj @@ -5,7 +5,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix - +