Skip to content

Commit

Permalink
H/3 and Quic AppContext switch (#55332)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ManickaP committed Jul 14, 2021
1 parent 5b0c6dd commit 1778ae2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal sealed class HttpConnectionSettings
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 :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
<Scenario>WasmTestOnBrowser</Scenario>
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,18 @@ private MsQuicApi(NativeApi* vtable)

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}");
Expand Down Expand Up @@ -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 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
</ItemGroup>
<ItemGroup>
<Compile Include="*.cs" />
</ItemGroup>
Expand Down

0 comments on commit 1778ae2

Please sign in to comment.