< Summary

Information
Class: System.Net.Http.HttpConnectionSettings
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpConnectionSettings.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 85
Coverable lines: 85
Total lines: 157
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()0%440%
CloneAndNormalize()0%12120%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpConnectionSettings.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.Collections.Generic;
 5using System.Diagnostics;
 6using System.Diagnostics.Metrics;
 7using System.IO;
 8using System.Net.Http.Metrics;
 9using System.Net.Security;
 10using System.Runtime.Versioning;
 11using System.Security.Principal;
 12using System.Threading;
 13using System.Threading.Tasks;
 14
 15namespace System.Net.Http
 16{
 17    /// <summary>Provides a state bag of settings for configuring HTTP connections.</summary>
 18    internal sealed class HttpConnectionSettings
 19    {
 020        internal DecompressionMethods _automaticDecompression = HttpHandlerDefaults.DefaultAutomaticDecompression;
 21
 022        internal bool _useCookies = HttpHandlerDefaults.DefaultUseCookies;
 23        internal CookieContainer? _cookieContainer;
 24
 025        internal bool _useProxy = HttpHandlerDefaults.DefaultUseProxy;
 26        internal IWebProxy? _proxy;
 27        internal ICredentials? _defaultProxyCredentials;
 28        internal bool _defaultCredentialsUsedForProxy;
 29        internal bool _defaultCredentialsUsedForServer;
 30
 031        internal bool _preAuthenticate = HttpHandlerDefaults.DefaultPreAuthenticate;
 32        internal ICredentials? _credentials;
 033        internal TokenImpersonationLevel _impersonationLevel = HttpHandlerDefaults.DefaultImpersonationLevel;   // this 
 34
 035        internal bool _allowAutoRedirect = HttpHandlerDefaults.DefaultAutomaticRedirection;
 036        internal int _maxAutomaticRedirections = HttpHandlerDefaults.DefaultMaxAutomaticRedirections;
 37
 038        internal int _maxConnectionsPerServer = HttpHandlerDefaults.DefaultMaxConnectionsPerServer;
 039        internal int _maxResponseDrainSize = HttpHandlerDefaults.DefaultMaxResponseDrainSize;
 040        internal TimeSpan _maxResponseDrainTime = HttpHandlerDefaults.DefaultResponseDrainTimeout;
 041        internal int _maxResponseHeadersLength = HttpHandlerDefaults.DefaultMaxResponseHeadersLength;
 42        internal IMeterFactory? _meterFactory;
 43        internal SocketsHttpHandlerMetrics? _metrics;
 44
 045        internal TimeSpan _pooledConnectionLifetime = HttpHandlerDefaults.DefaultPooledConnectionLifetime;
 046        internal TimeSpan _pooledConnectionIdleTimeout = HttpHandlerDefaults.DefaultPooledConnectionIdleTimeout;
 047        internal TimeSpan _expect100ContinueTimeout = HttpHandlerDefaults.DefaultExpect100ContinueTimeout;
 048        internal TimeSpan _keepAlivePingTimeout = HttpHandlerDefaults.DefaultKeepAlivePingTimeout;
 049        internal TimeSpan _keepAlivePingDelay = HttpHandlerDefaults.DefaultKeepAlivePingDelay;
 050        internal HttpKeepAlivePingPolicy _keepAlivePingPolicy = HttpHandlerDefaults.DefaultKeepAlivePingPolicy;
 051        internal TimeSpan _connectTimeout = HttpHandlerDefaults.DefaultConnectTimeout;
 52
 53        internal HeaderEncodingSelector<HttpRequestMessage>? _requestHeaderEncodingSelector;
 54        internal HeaderEncodingSelector<HttpRequestMessage>? _responseHeaderEncodingSelector;
 55
 056        internal DistributedContextPropagator? _activityHeadersPropagator = DistributedContextPropagator.Current;
 57
 58        internal Version _maxHttpVersion;
 59
 60        internal SslClientAuthenticationOptions? _sslOptions;
 61
 62        internal bool _enableMultipleHttp2Connections;
 63
 64        internal bool _enableMultipleHttp3Connections;
 65
 66        internal Func<SocketsHttpConnectionContext, CancellationToken, ValueTask<Stream>>? _connectCallback;
 67        internal Func<SocketsHttpPlaintextStreamFilterContext, CancellationToken, ValueTask<Stream>>? _plaintextStreamFi
 68
 69        internal IDictionary<string, object?>? _properties;
 70
 71        // Http2 flow control settings:
 072        internal int _initialHttp2StreamWindowSize = HttpHandlerDefaults.DefaultInitialHttp2StreamWindowSize;
 73
 74        internal ClientCertificateOption _clientCertificateOptions;
 75
 076        public HttpConnectionSettings()
 077        {
 078            bool allowHttp2 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp2;
 079            bool allowHttp3 = GlobalHttpSettings.SocketsHttpHandler.AllowHttp3;
 080            _maxHttpVersion =
 081                allowHttp3 && allowHttp2 ? HttpVersion.Version30 :
 082                allowHttp2 ? HttpVersion.Version20 :
 083                HttpVersion.Version11;
 84
 085            _clientCertificateOptions = ClientCertificateOption.Automatic;
 086        }
 87
 88        /// <summary>Creates a copy of the settings but with some values normalized to suit the implementation.</summary
 89        public HttpConnectionSettings CloneAndNormalize()
 090        {
 91            // Force creation of the cookie container if needed, so the original and clone share the same instance.
 092            if (_useCookies && _cookieContainer == null)
 093            {
 094                _cookieContainer = new CookieContainer();
 095            }
 96
 097            var settings = new HttpConnectionSettings()
 098            {
 099                _allowAutoRedirect = _allowAutoRedirect,
 0100                _automaticDecompression = _automaticDecompression,
 0101                _cookieContainer = _cookieContainer,
 0102                _connectTimeout = _connectTimeout,
 0103                _credentials = _credentials,
 0104                _defaultProxyCredentials = _defaultProxyCredentials,
 0105                _expect100ContinueTimeout = _expect100ContinueTimeout,
 0106                _maxAutomaticRedirections = _maxAutomaticRedirections,
 0107                _maxConnectionsPerServer = _maxConnectionsPerServer,
 0108                _maxHttpVersion = _maxHttpVersion,
 0109                _maxResponseDrainSize = _maxResponseDrainSize,
 0110                _maxResponseDrainTime = _maxResponseDrainTime,
 0111                _maxResponseHeadersLength = _maxResponseHeadersLength,
 0112                _pooledConnectionLifetime = _pooledConnectionLifetime,
 0113                _pooledConnectionIdleTimeout = _pooledConnectionIdleTimeout,
 0114                _preAuthenticate = _preAuthenticate,
 0115                _properties = _properties,
 0116                _proxy = _proxy,
 0117                _sslOptions = _sslOptions?.ShallowClone(), // shallow clone the options for basic prevention of mutation
 0118                _useCookies = _useCookies,
 0119                _useProxy = _useProxy,
 0120                _keepAlivePingTimeout = _keepAlivePingTimeout,
 0121                _keepAlivePingDelay = _keepAlivePingDelay,
 0122                _keepAlivePingPolicy = _keepAlivePingPolicy,
 0123                _requestHeaderEncodingSelector = _requestHeaderEncodingSelector,
 0124                _responseHeaderEncodingSelector = _responseHeaderEncodingSelector,
 0125                _enableMultipleHttp2Connections = _enableMultipleHttp2Connections,
 0126                _enableMultipleHttp3Connections = _enableMultipleHttp3Connections,
 0127                _connectCallback = _connectCallback,
 0128                _plaintextStreamFilter = _plaintextStreamFilter,
 0129                _initialHttp2StreamWindowSize = _initialHttp2StreamWindowSize,
 0130                _activityHeadersPropagator = _activityHeadersPropagator,
 0131                _defaultCredentialsUsedForProxy = _proxy != null && (_proxy.Credentials == CredentialCache.DefaultCreden
 0132                _defaultCredentialsUsedForServer = _credentials == CredentialCache.DefaultCredentials,
 0133                _clientCertificateOptions = _clientCertificateOptions,
 0134                _impersonationLevel = _impersonationLevel,
 0135            };
 136
 0137            if (GlobalHttpSettings.MetricsHandler.IsGloballyEnabled)
 0138            {
 0139                settings._meterFactory = _meterFactory;
 0140                settings._metrics = _metrics;
 0141            }
 142
 0143            return settings;
 0144        }
 145
 0146        public int MaxResponseHeadersByteLength => (int)Math.Min(int.MaxValue, _maxResponseHeadersLength * 1024L);
 147
 0148        public bool EnableMultipleHttp2Connections => _enableMultipleHttp2Connections;
 149
 0150        public bool EnableMultipleHttp3Connections => _enableMultipleHttp3Connections;
 151
 152        [SupportedOSPlatform("windows")]
 153        [SupportedOSPlatform("linux")]
 154        [SupportedOSPlatform("macos")]
 0155        internal byte[] Http3SettingsFrame => field ??= Http3Connection.BuildSettingsFrame(this);
 156    }
 157}