diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs index 3acfe7f189f4a..1a3b68c55c711 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs @@ -76,6 +76,9 @@ internal sealed class HttpConnectionPool : IDisposable private byte[]? _http2AltSvcOriginUri; internal readonly byte[]? _http2EncodedAuthorityHostHeader; + [SupportedOSPlatformGuard("linux")] + [SupportedOSPlatformGuard("macOS")] + [SupportedOSPlatformGuard("Windows")] private readonly bool _http3Enabled; private Http3Connection? _http3Connection; private SemaphoreSlim? _http3ConnectionCreateLock; diff --git a/src/libraries/System.Net.Http/tests/TrimmingTests/HttpClientTest.cs b/src/libraries/System.Net.Http/tests/TrimmingTests/HttpClientTest.cs index f6ec0a315f233..7ded3b5b65be8 100644 --- a/src/libraries/System.Net.Http/tests/TrimmingTests/HttpClientTest.cs +++ b/src/libraries/System.Net.Http/tests/TrimmingTests/HttpClientTest.cs @@ -9,6 +9,11 @@ class Program { + [SupportedOSPlatformGuard("linux")] + [SupportedOSPlatformGuard("macOS")] + [SupportedOSPlatformGuard("Windows")] + private static bool IsHttp3Supported => (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS(); + static async Task Main(string[] args) { using var client = new HttpClient(); @@ -19,12 +24,7 @@ static async Task Main(string[] args) const string quicDll = "System.Net.Quic.dll"; var quicDllExists = File.Exists(Path.Combine(AppContext.BaseDirectory, quicDll)); - [SupportedOSPlatformGuard("linux")] - [SupportedOSPlatformGuard("macOS")] - [SupportedOSPlatformGuard("Windows")] - private readonly bool _http3Enabled = (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS(); - - if (_http3Enabled) + if (IsHttp3Supported) { Console.WriteLine($"Expected {quicDll} is {(quicDllExists ? "present - OK" : "missing - BAD")}."); return quicDllExists ? 100 : -1;