Skip to content

Commit 1778ae2

Browse files
authored
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
1 parent 5b0c6dd commit 1778ae2

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/GlobalHttpSettings.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ internal static class SocketsHttpHandler
2626
"DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2SUPPORT",
2727
true);
2828

29-
// Default to allowing draft HTTP/3, but enable that to be overridden
30-
// by an AppContext switch, or by an environment variable being set to false/0.
31-
public static bool AllowDraftHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
32-
"System.Net.SocketsHttpHandler.Http3DraftSupport",
33-
"DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3DRAFTSUPPORT",
34-
true);
29+
// Default to disable HTTP/3 (and by an extent QUIC), but enable that to be overridden
30+
// by an AppContext switch, or by an environment variable being set to true/1.
31+
public static bool AllowHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
32+
"System.Net.SocketsHttpHandler.Http3Support",
33+
"DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT",
34+
false);
3535

3636
// Switch to disable the HTTP/2 dynamic window scaling algorithm. Enabled by default.
3737
public static bool DisableDynamicHttp2WindowSizing { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal sealed class HttpConnectionSettings
7070
public HttpConnectionSettings()
7171
{
7272
bool allowHttp2 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp2;
73-
bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowDraftHttp3;
73+
bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp3;
7474
_maxHttpVersion =
7575
allowHttp3 && allowHttp2 ? HttpVersion.Version30 :
7676
allowHttp2 ? HttpVersion.Version20 :

src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
1010
</PropertyGroup>
1111

12+
<ItemGroup>
13+
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
14+
</ItemGroup>
15+
1216
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
1317
<Scenario>WasmTestOnBrowser</Scenario>
1418
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>

src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
1216
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />

src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,18 @@ private MsQuicApi(NativeApi* vtable)
125125

126126
static MsQuicApi()
127127
{
128-
if (OperatingSystem.IsWindows() && !IsWindowsVersionSupported())
128+
if (!IsHttp3Enabled())
129129
{
130-
IsQuicSupported = false;
130+
if (NetEventSource.Log.IsEnabled())
131+
{
132+
NetEventSource.Info(null, $"HTTP/3 and QUIC is not enabled, see 'System.Net.SocketsHttpHandler.Http3Support' AppContext switch.");
133+
}
131134

135+
return;
136+
}
137+
138+
if (OperatingSystem.IsWindows() && !IsWindowsVersionSupported())
139+
{
132140
if (NetEventSource.Log.IsEnabled())
133141
{
134142
NetEventSource.Info(null, $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {MinWindowsVersion}");
@@ -163,6 +171,34 @@ static MsQuicApi()
163171
}
164172
}
165173

174+
// Note that this is copy-pasted from S.N.Http just to hide S.N.Quic behind the same AppContext switch
175+
// since this library is considered "private" for 6.0.
176+
// We should get rid of this once S.N.Quic API surface is officially exposed.
177+
private static bool IsHttp3Enabled()
178+
{
179+
bool value;
180+
181+
// First check for the AppContext switch, giving it priority over the environment variable.
182+
if (AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3Support", out value))
183+
{
184+
return value;
185+
}
186+
187+
// AppContext switch wasn't used. Check the environment variable.
188+
string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT");
189+
190+
if (bool.TryParse(envVar, out value))
191+
{
192+
return value;
193+
}
194+
else if (uint.TryParse(envVar, out uint intVal))
195+
{
196+
return intVal != 0;
197+
}
198+
199+
return false;
200+
}
201+
166202
private static bool IsWindowsVersionSupported() => OperatingSystem.IsWindowsVersionAtLeast(MinWindowsVersion.Major,
167203
MinWindowsVersion.Minor, MinWindowsVersion.Build, MinWindowsVersion.Revision);
168204

src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
55
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
66
</PropertyGroup>
7+
<ItemGroup>
8+
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
9+
</ItemGroup>
710
<ItemGroup>
811
<Compile Include="*.cs" />
912
</ItemGroup>

0 commit comments

Comments
 (0)