From 1778ae292f58ff0c88c599f32c65383ff92ef746 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marie=20P=C3=ADchov=C3=A1?= <11718369+ManickaP@users.noreply.github.com> Date: Wed, 14 Jul 2021 09:19:45 +0200 Subject: [PATCH] H/3 and Quic AppContext switch (#55332) * Renamed AllowDraftHttp3 to AllowHttp3AndQuic app context switch * Usage of AllowHttp3AndQuic switch in S.N.Quic and enabling it in tests * Renamed AppContext switch to Http3Support --- .../src/System/Net/Http/GlobalHttpSettings.cs | 12 +++--- .../HttpConnectionSettings.cs | 2 +- .../System.Net.Http.Functional.Tests.csproj | 4 ++ .../StressTests/HttpStress/HttpStress.csproj | 4 ++ .../MsQuic/Internal/MsQuicApi.cs | 40 ++++++++++++++++++- .../System.Net.Quic.Functional.Tests.csproj | 3 ++ 6 files changed, 56 insertions(+), 9 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 7382f4ca0da..664d296dcb6 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 @@ namespace System.Net.Http "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 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 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. 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 a24a6403b29..410acc16b69 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 @@ -70,7 +70,7 @@ namespace System.Net.Http public HttpConnectionSettings() { bool allowHttp2 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp2; - bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowDraftHttp3; + 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 b3413cbef30..667b35e9a8a 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 db333cc634f..80b4aa21b10 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 + + + + 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 cba34f6dbba..b691d3c5c14 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 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal static MsQuicApi() { - if (OperatingSystem.IsWindows() && !IsWindowsVersionSupported()) + if (!IsHttp3Enabled()) { - IsQuicSupported = false; + if (NetEventSource.Log.IsEnabled()) + { + NetEventSource.Info(null, $"HTTP/3 and QUIC is not enabled, see 'System.Net.SocketsHttpHandler.Http3Support' 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 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal } } + // 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 IsHttp3Enabled() + { + bool value; + + // First check for the AppContext switch, giving it priority over the environment variable. + 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_HTTP3SUPPORT"); + + 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 2a17894a555..583b2b6c486 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 + + + -- 2.34.1