< Summary

Information
Class: System.Net.Http.GlobalHttpSettings
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\GlobalHttpSettings.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 56
Coverable lines: 56
Total lines: 119
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
.cctor()100%110%
.cctor()0%660%
GetMaxHttp2StreamWindowSize()0%220%
GetHttp2StreamWindowScaleThresholdMultiplier()0%220%
GetMaxConnectionsPerServer()0%220%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\GlobalHttpSettings.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Runtime.Versioning;
 7
 8namespace System.Net.Http
 9{
 10    /// <summary>
 11    /// Exposes process-wide settings for handlers.
 12    /// </summary>
 13    internal static class GlobalHttpSettings
 14    {
 15        internal static class DiagnosticsHandler
 16        {
 17            [FeatureSwitchDefinition("System.Net.Http.EnableActivityPropagation")]
 018            public static bool EnableActivityPropagation { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
 019                "System.Net.Http.EnableActivityPropagation",
 020                "DOTNET_SYSTEM_NET_HTTP_ENABLEACTIVITYPROPAGATION",
 021                true);
 22        }
 23
 24        internal static class MetricsHandler
 25        {
 26            [FeatureSwitchDefinition("System.Diagnostics.Metrics.Meter.IsSupported")]
 027            public static bool IsGloballyEnabled { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
 028                "System.Diagnostics.Metrics.Meter.IsSupported",
 029                true);
 30        }
 31
 32        internal static class SocketsHttpHandler
 33        {
 34#if !TARGET_BROWSER && !TARGET_WASI
 35            // Default to allowing HTTP/2, but enable that to be overridden by an
 36            // AppContext switch, or by an environment variable being set to false/0.
 037            public static bool AllowHttp2 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
 038                "System.Net.Http.SocketsHttpHandler.Http2Support",
 039                "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2SUPPORT",
 040                true);
 41
 42            // Default to allowing HTTP/3 on platforms where we have QUIC, but enable that to be overridden by an
 43            // AppContext switch, or by an environment variable being set to false/0.
 44            [SupportedOSPlatformGuard("linux")]
 45            [SupportedOSPlatformGuard("macOS")]
 46            [SupportedOSPlatformGuard("windows")]
 47            [FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]
 048            public static bool AllowHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch(
 049                "System.Net.SocketsHttpHandler.Http3Support",
 050                "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT",
 051                (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingS
 52
 53            // Switch to disable the HTTP/2 dynamic window scaling algorithm. Enabled by default.
 054            public static bool DisableDynamicHttp2WindowSizing { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch
 055                "System.Net.SocketsHttpHandler.Http2FlowControl.DisableDynamicWindowSizing",
 056                "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2FLOWCONTROL_DISABLEDYNAMICWINDOWSIZING",
 057                false);
 58
 59            // The maximum size of the HTTP/2 stream receive window. Defaults to 16 MB.
 060            public static int MaxHttp2StreamWindowSize { get; } = GetMaxHttp2StreamWindowSize();
 61
 62            // Defaults to 1.0. Higher values result in shorter window, but slower downloads.
 063            public static double Http2StreamWindowScaleThresholdMultiplier { get; } = GetHttp2StreamWindowScaleThreshold
 64
 065            public static int PendingConnectionTimeoutOnRequestCompletion { get; } = RuntimeSettingParser.QueryRuntimeSe
 066                "System.Net.SocketsHttpHandler.PendingConnectionTimeoutOnRequestCompletion",
 067                "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_PENDINGCONNECTIONTIMEOUTONREQUESTCOMPLETION", 5000);
 68
 69            public const int DefaultHttp2MaxStreamWindowSize = 16 * 1024 * 1024;
 70            public const double DefaultHttp2StreamWindowScaleThresholdMultiplier = 1.0;
 71
 72            private static int GetMaxHttp2StreamWindowSize()
 073            {
 074                int value = RuntimeSettingParser.ParseInt32EnvironmentVariableValue(
 075                    "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_MAXSTREAMWINDOWSIZE",
 076                    DefaultHttp2MaxStreamWindowSize);
 77
 78                // Disallow small values:
 079                if (value < HttpHandlerDefaults.DefaultInitialHttp2StreamWindowSize)
 080                {
 081                    value = HttpHandlerDefaults.DefaultInitialHttp2StreamWindowSize;
 082                }
 083                return value;
 084            }
 85
 86            private static double GetHttp2StreamWindowScaleThresholdMultiplier()
 087            {
 088                double value = RuntimeSettingParser.ParseDoubleEnvironmentVariableValue(
 089                    "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_STREAMWINDOWSCALETHRESHOLDMULTIPLIER",
 090                    DefaultHttp2StreamWindowScaleThresholdMultiplier);
 91
 92                // Disallow negative values:
 093                if (value < 0)
 094                {
 095                    value = DefaultHttp2StreamWindowScaleThresholdMultiplier;
 096                }
 097                return value;
 098            }
 99#endif
 100
 0101            public static int MaxConnectionsPerServer { get; } = GetMaxConnectionsPerServer();
 102
 103            private static int GetMaxConnectionsPerServer()
 0104            {
 0105                int value = RuntimeSettingParser.QueryRuntimeSettingInt32(
 0106                    "System.Net.SocketsHttpHandler.MaxConnectionsPerServer",
 0107                    "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_MAXCONNECTIONSPERSERVER",
 0108                    int.MaxValue);
 109
 110                // Disallow invalid values
 0111                if (value < 1)
 0112                {
 0113                    value = int.MaxValue;
 0114                }
 0115                return value;
 0116            }
 117        }
 118    }
 119}