| | | 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 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Diagnostics.CodeAnalysis; |
| | | 6 | | using System.Runtime.Versioning; |
| | | 7 | | |
| | | 8 | | namespace 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")] |
| | 0 | 18 | | public static bool EnableActivityPropagation { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( |
| | 0 | 19 | | "System.Net.Http.EnableActivityPropagation", |
| | 0 | 20 | | "DOTNET_SYSTEM_NET_HTTP_ENABLEACTIVITYPROPAGATION", |
| | 0 | 21 | | true); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | internal static class MetricsHandler |
| | | 25 | | { |
| | | 26 | | [FeatureSwitchDefinition("System.Diagnostics.Metrics.Meter.IsSupported")] |
| | 0 | 27 | | public static bool IsGloballyEnabled { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( |
| | 0 | 28 | | "System.Diagnostics.Metrics.Meter.IsSupported", |
| | 0 | 29 | | 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. |
| | 0 | 37 | | public static bool AllowHttp2 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( |
| | 0 | 38 | | "System.Net.Http.SocketsHttpHandler.Http2Support", |
| | 0 | 39 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2SUPPORT", |
| | 0 | 40 | | 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")] |
| | 0 | 48 | | public static bool AllowHttp3 { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch( |
| | 0 | 49 | | "System.Net.SocketsHttpHandler.Http3Support", |
| | 0 | 50 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT", |
| | 0 | 51 | | (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingS |
| | | 52 | | |
| | | 53 | | // Switch to disable the HTTP/2 dynamic window scaling algorithm. Enabled by default. |
| | 0 | 54 | | public static bool DisableDynamicHttp2WindowSizing { get; } = RuntimeSettingParser.QueryRuntimeSettingSwitch |
| | 0 | 55 | | "System.Net.SocketsHttpHandler.Http2FlowControl.DisableDynamicWindowSizing", |
| | 0 | 56 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2FLOWCONTROL_DISABLEDYNAMICWINDOWSIZING", |
| | 0 | 57 | | false); |
| | | 58 | | |
| | | 59 | | // The maximum size of the HTTP/2 stream receive window. Defaults to 16 MB. |
| | 0 | 60 | | public static int MaxHttp2StreamWindowSize { get; } = GetMaxHttp2StreamWindowSize(); |
| | | 61 | | |
| | | 62 | | // Defaults to 1.0. Higher values result in shorter window, but slower downloads. |
| | 0 | 63 | | public static double Http2StreamWindowScaleThresholdMultiplier { get; } = GetHttp2StreamWindowScaleThreshold |
| | | 64 | | |
| | 0 | 65 | | public static int PendingConnectionTimeoutOnRequestCompletion { get; } = RuntimeSettingParser.QueryRuntimeSe |
| | 0 | 66 | | "System.Net.SocketsHttpHandler.PendingConnectionTimeoutOnRequestCompletion", |
| | 0 | 67 | | "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() |
| | 0 | 73 | | { |
| | 0 | 74 | | int value = RuntimeSettingParser.ParseInt32EnvironmentVariableValue( |
| | 0 | 75 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_MAXSTREAMWINDOWSIZE", |
| | 0 | 76 | | DefaultHttp2MaxStreamWindowSize); |
| | | 77 | | |
| | | 78 | | // Disallow small values: |
| | 0 | 79 | | if (value < HttpHandlerDefaults.DefaultInitialHttp2StreamWindowSize) |
| | 0 | 80 | | { |
| | 0 | 81 | | value = HttpHandlerDefaults.DefaultInitialHttp2StreamWindowSize; |
| | 0 | 82 | | } |
| | 0 | 83 | | return value; |
| | 0 | 84 | | } |
| | | 85 | | |
| | | 86 | | private static double GetHttp2StreamWindowScaleThresholdMultiplier() |
| | 0 | 87 | | { |
| | 0 | 88 | | double value = RuntimeSettingParser.ParseDoubleEnvironmentVariableValue( |
| | 0 | 89 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_STREAMWINDOWSCALETHRESHOLDMULTIPLIER", |
| | 0 | 90 | | DefaultHttp2StreamWindowScaleThresholdMultiplier); |
| | | 91 | | |
| | | 92 | | // Disallow negative values: |
| | 0 | 93 | | if (value < 0) |
| | 0 | 94 | | { |
| | 0 | 95 | | value = DefaultHttp2StreamWindowScaleThresholdMultiplier; |
| | 0 | 96 | | } |
| | 0 | 97 | | return value; |
| | 0 | 98 | | } |
| | | 99 | | #endif |
| | | 100 | | |
| | 0 | 101 | | public static int MaxConnectionsPerServer { get; } = GetMaxConnectionsPerServer(); |
| | | 102 | | |
| | | 103 | | private static int GetMaxConnectionsPerServer() |
| | 0 | 104 | | { |
| | 0 | 105 | | int value = RuntimeSettingParser.QueryRuntimeSettingInt32( |
| | 0 | 106 | | "System.Net.SocketsHttpHandler.MaxConnectionsPerServer", |
| | 0 | 107 | | "DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_MAXCONNECTIONSPERSERVER", |
| | 0 | 108 | | int.MaxValue); |
| | | 109 | | |
| | | 110 | | // Disallow invalid values |
| | 0 | 111 | | if (value < 1) |
| | 0 | 112 | | { |
| | 0 | 113 | | value = int.MaxValue; |
| | 0 | 114 | | } |
| | 0 | 115 | | return value; |
| | 0 | 116 | | } |
| | | 117 | | } |
| | | 118 | | } |
| | | 119 | | } |