61 if (result.
Waiter.TrySetException(e))
77 if (result.
Waiter.TrySetResult(connection))
171 SslApplicationProtocol.Http11
298 _sslOptionsHttp11.ApplicationProtocols =
null;
320 Trace(
$"{this}",
".ctor");
339 sslClientAuthenticationOptions.TargetHost =
sslHostName;
344 System.
Net.
NetEventSource.
Info(
poolManager,
$"Win7OrWin2K8R2 platform, Changing default TLS protocols to {SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13}",
"ConstructSslOptions");
346 sslClientAuthenticationOptions.EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 |
SslProtocols.Tls13;
379 Trace(
"Creating new HTTP/1.1 connection for pool.",
"AddHttp11ConnectionAsync");
437 httpConnection.Trace(
"Found expired HTTP/1.1 connection in pool.",
"GetHttp11ConnectionAsync");
446 httpConnection.Trace(
"Found invalid HTTP/1.1 connection in pool.",
"GetHttp11ConnectionAsync");
453 httpConnection.Trace(
"Found usable HTTP/1.1 connection in pool.",
"GetHttp11ConnectionAsync");
459 Trace(
"No available HTTP/1.1 connections; request queued.",
"GetHttp11ConnectionAsync");
479 Trace(
"Server does not support HTTP2; disabling HTTP2 use and proceeding with HTTP/1.1 connection",
"HandleHttp11Downgrade");
504 Trace(
"Discarding downgraded HTTP/1.1 connection because HTTP/1.1 connection limit is exceeded",
"HandleHttp11Downgrade");
530 Trace(
"Creating new HTTP/2 connection for pool.",
"AddHttp2ConnectionAsync");
619 http2Connection.Trace(
"Found expired HTTP/2 connection in pool.",
"GetHttp2ConnectionAsync");
628 http2Connection.Trace(
"Found HTTP/2 connection in pool without available streams.",
"GetHttp2ConnectionAsync");
648 http2Connection.Trace(
"Found usable HTTP/2 connection in pool.",
"GetHttp2ConnectionAsync");
654 Trace(
"No available HTTP/2 connections; request queued.",
"GetHttp2ConnectionAsync");
682 Trace(
"Using existing HTTP3 connection.",
"GetHttp3ConnectionAsync");
689 http3Connection.Trace(
"Found expired HTTP3 connection.",
"GetHttp3ConnectionAsync");
711 Trace(
"Using existing HTTP3 connection.",
"GetHttp3ConnectionAsync");
717 Trace(
"Attempting new HTTP3 connection.",
"GetHttp3ConnectionAsync");
732 Trace(
"New HTTP3 connection established.",
"GetHttp3ConnectionAsync");
836 Trace(
$"MaxConnectionFailureRetries limit of {3} hit. Retryable request will not be retried. Exception: {ex}",
"SendWithVersionDetectionAndRetryAsync");
843 Trace(
$"Retry attempt {retryCount} after connection failure. Connection exception: {ex}",
"SendWithVersionDetectionAndRetryAsync");
848 if (
request.VersionPolicy != 0)
854 Trace(
$"Retrying request because server requested version fallback: {ex2}",
"SendWithVersionDetectionAndRetryAsync");
862 Trace(
$"Retrying request on another HTTP/2 connection after active streams limit is reached on existing one: {ex3}",
"SendWithVersionDetectionAndRetryAsync");
911 if (
dueTime.Ticks > 25920000000000
L)
933 target.ExpireAltSvcAuthority();
1132 Trace(
"ConnectCallback completing asynchronously for a synchronous request.",
"ConnectToTcpHostAsync");
1201 Trace(
"PlaintextStreamFilter completing asynchronously for a synchronous request.",
"ApplyPlaintextFilterAsync");
1251 httpRequestMessage.Headers.Host =
$"{_originAuthority.IdnHost}:{_originAuthority.Port}";
1291 Trace(
"HTTP/1.1 connection failed",
"HandleHttp11ConnectionFailure");
1306 Trace(
"HTTP2 connection failed",
"HandleHttp2ConnectionFailure");
1330 connection.
Trace(
"",
"InvalidateHttp2Connection");
1377 connection.
Trace(
"Disposing HTTP/1.1 connection return to pool. Connection lifetime expired.",
"ReturnHttp11Connection");
1392 connection.
Trace(
"Dequeued waiting HTTP/1.1 request.",
"ReturnHttp11Connection");
1401 connection.
Trace(
"Put connection in pool.",
"ReturnHttp11Connection");
1407 connection.
Trace(
"Disposing connection returned to pool. Pool was disposed.",
"ReturnHttp11Connection");
1427 connection.
Trace(
"Disposing HTTP/2 connection return to pool. Connection lifetime expired.",
"ReturnHttp2Connection");
1461 connection.
Trace(
"Dequeued waiting HTTP/2 request.",
"ReturnHttp2Connection");
1479 connection.
Trace(
"Put HTTP/2 connection in pool.",
"ReturnHttp2Connection");
1488 connection.
Trace(
"Disposing HTTP/2 connection returned to pool. Pool was disposed.",
"ReturnHttp2Connection");
1502 connection.
Trace(
"",
"DisableHttp2Connection");
1509 connection.
Trace(
$"WaitForAvailableStreamsAsync completed, {"usable"}={flag}",
"DisableHttp2Connection");
1524 connection.
Trace(
"HTTP2 connection no longer usable",
"DisableHttp2Connection");
1551 Trace(
"Disposing pool.",
"Dispose");
1622 connection.
Trace(
$"Scavenging connection. Idle {TimeSpan.FromMilliseconds(idleTicks)} > {pooledConnectionIdleTimeout}.",
"CleanCacheAndDisposeIfUnused");
1634 connection.
Trace(
$"Scavenging connection. Lifetime {TimeSpan.FromMilliseconds(lifetimeTicks)} > {pooledConnectionLifetime}.",
"CleanCacheAndDisposeIfUnused");
1643 connection.
Trace(
"Scavenging connection. Unexpected data or EOF received.",
"CleanCacheAndDisposeIfUnused");
1674 num2 = list.Count - i;
1687 if (version.
Major == 6)
1689 return version.Minor == 1;
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static OperatingSystem OSVersion
static CultureInfo InvariantCulture
static readonly Version Version20
static readonly Version Version11
static ValueTask< HttpResponseMessage > SendWithRequestAuthAsync(HttpRequestMessage request, bool async, ICredentials credentials, bool preAuthenticate, HttpConnectionPool pool, CancellationToken cancellationToken)
static Task< HttpResponseMessage > SendWithNtProxyAuthAsync(HttpRequestMessage request, Uri proxyUri, bool async, ICredentials proxyCredentials, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
static Task< HttpResponseMessage > SendWithNtConnectionAuthAsync(HttpRequestMessage request, bool async, ICredentials credentials, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
static ValueTask< HttpResponseMessage > SendWithProxyAuthAsync(HttpRequestMessage request, Uri proxyUri, bool async, ICredentials proxyCredentials, bool doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
static Exception CreateOperationCanceledException(Exception innerException, CancellationToken cancellationToken)
static Exception CreateWrappedException(Exception error, string host, int port, CancellationToken cancellationToken)
static async ValueTask< SslStream > EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)
static async ValueTask< QuicConnection > ConnectQuicAsync(HttpRequestMessage request, QuicImplementationProvider quicImplementationProvider, DnsEndPoint endPoint, SslClientAuthenticationOptions clientAuthenticationOptions, CancellationToken cancellationToken)
static byte[] EncodeLiteralHeaderFieldWithoutIndexingToAllocatedArray(int index)
ValueTask WaitForShutdownAsync()
ValueTask< bool > WaitForAvailableStreamsAsync()
override void Trace(string message, [CallerMemberName] string memberName=null)
async Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
long GetLifetimeTicks(long nowTicks)
void Trace(string message, [CallerMemberName] string memberName=null)
long GetIdleTicks(long nowTicks)
virtual bool CheckUsabilityOnScavenge()
ICredentials ProxyCredentials
ValueTask< HttpResponseMessage > SendProxyConnectAsync(HttpRequestMessage request, Uri proxyUri, bool async, CancellationToken cancellationToken)
HttpConnectionSettings Settings
void StartMonitoringNetworkChanges()
readonly SslClientAuthenticationOptions _sslOptionsHttp2
RequestQueue< Http2Connection > _http2RequestQueue
bool _pendingHttp2Connection
CredentialCache PreAuthCredentials
static readonly List< SslApplicationProtocol > s_http2ApplicationProtocols
Task< HttpResponseMessage > SendWithNtProxyAuthAsync(HttpConnection connection, HttpRequestMessage request, bool async, CancellationToken cancellationToken)
readonly SslClientAuthenticationOptions _sslOptionsHttp3
async ValueTask<(Socket, Stream)> ConnectToTcpHostAsync(string host, int port, HttpRequestMessage initialRequest, bool async, CancellationToken cancellationToken)
async Task AddHttp2ConnectionAsync(HttpRequestMessage request)
async ValueTask< HttpResponseMessage > SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
ICredentials ProxyCredentials
static void ThrowGetVersionException(HttpRequestMessage request, int desiredVersion)
void InvalidateHttp11Connection(HttpConnection connection, bool disposing=true)
static Exception CreateConnectTimeoutException(OperationCanceledException oce)
readonly int _maxHttp11Connections
readonly HttpConnectionKind _kind
void ProcessAltSvc(HttpResponseMessage response)
HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionKind kind, string host, int port, string sslHostName, Uri proxyUri)
async ValueTask< Http3Connection > GetHttp3ConnectionAsync(HttpRequestMessage request, HttpAuthority authority, CancellationToken cancellationToken)
static readonly List< SslApplicationProtocol > s_http3ApplicationProtocols
void InvalidateHttp3Connection(Http3Connection connection)
void BlocklistAuthority(HttpAuthority badAuthority)
static readonly List< SslApplicationProtocol > s_http2OnlyApplicationProtocols
async ValueTask< HttpResponseMessage > TrySendUsingHttp3Async(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
List< Http2Connection > _availableHttp2Connections
bool CheckExpirationOnReturn(HttpConnectionBase connection)
bool EnableMultipleHttp2Connections
async ValueTask< Stream > EstablishProxyTunnelAsync(bool async, HttpRequestHeaders headers, CancellationToken cancellationToken)
readonly byte[] _http2EncodedAuthorityHostHeader
void ReturnHttp11Connection(HttpConnection connection, bool isNewConnection=false)
byte[] Http2AltSvcOriginUri
readonly bool _http3Enabled
Timer _authorityExpireTimer
async Task HandleHttp11Downgrade(HttpRequestMessage request, Socket socket, Stream stream, TransportContext transportContext, CancellationToken cancellationToken)
CancellationTokenSource GetConnectTimeoutCancellationTokenSource()
Task< HttpResponseMessage > SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
async ValueTask<(Socket, Stream, TransportContext)> ConnectAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
Http3Connection _http3Connection
void ExpireAltSvcAuthority()
bool CleanCacheAndDisposeIfUnused()
int _pendingHttp11ConnectionCount
async ValueTask< HttpConnection > CreateHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
int _associatedHttp11ConnectionCount
static bool GetIsWindows7Or2008R2()
void HandleHttp2ConnectionFailure(Exception e)
static SslClientAuthenticationOptions ConstructSslOptions(HttpConnectionPoolManager poolManager, string sslHostName)
override string ToString()
bool CheckExpirationOnGet(HttpConnectionBase connection)
readonly List< HttpConnection > _availableHttp11Connections
SslClientAuthenticationOptions GetSslOptionsForRequest(HttpRequestMessage request)
async ValueTask< Http2Connection > GetHttp2ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
async ValueTask<(Socket socket, Stream stream)> EstablishSocksTunnel(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
void InvalidateHttp2Connection(Http2Connection connection)
void Trace(string message, [CallerMemberName] string memberName=null)
async Task AddHttp11ConnectionAsync(HttpRequestMessage request)
volatile HttpAuthority _http3Authority
void ReturnHttp2Connection(Http2Connection connection, bool isNewConnection)
void HandleAltSvc(IEnumerable< string > altSvcHeaderValues, TimeSpan? responseAge)
byte[] HostHeaderValueBytes
readonly byte[] _hostHeaderValueBytes
HttpConnectionSettings Settings
static readonly bool s_isWindows7Or2008R2
readonly HttpConnectionPoolManager _poolManager
byte[] _http2AltSvcOriginUri
volatile HashSet< HttpAuthority > _altSvcBlocklist
CancellationTokenSource _altSvcBlocklistTimerCancellation
async ValueTask< HttpConnection > GetHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
ValueTask< HttpResponseMessage > SendWithProxyAuthAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
SemaphoreSlim _http3ConnectionCreateLock
RequestQueue< HttpConnection > _http11RequestQueue
async ValueTask< Http2Connection > ConstructHttp2ConnectionAsync(Stream stream, HttpRequestMessage request, CancellationToken cancellationToken)
bool IsAltSvcBlocked(HttpAuthority authority)
static bool IsHttp3Supported()
bool _usedSinceLastCleanup
void CheckForHttp11ConnectionInjection()
void HandleHttp11ConnectionFailure(Exception e)
async ValueTask< Stream > ApplyPlaintextFilterAsync(bool async, Stream stream, Version httpVersion, HttpRequestMessage request, CancellationToken cancellationToken)
readonly HttpAuthority _originAuthority
int _associatedHttp2ConnectionCount
async ValueTask< HttpConnection > ConstructHttp11ConnectionAsync(bool async, Socket socket, Stream stream, TransportContext transportContext, HttpRequestMessage request, CancellationToken cancellationToken)
volatile bool _altSvcEnabled
void DisableHttp2Connection(Http2Connection connection)
readonly SslClientAuthenticationOptions _sslOptionsHttp2Only
readonly SslClientAuthenticationOptions _sslOptionsHttp11
void CheckForHttp2ConnectionInjection()
readonly byte[] _http3EncodedAuthorityHostHeader
ValueTask< HttpResponseMessage > SendAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
bool EnableMultipleHttp2Connections
QuicImplementationProvider _quicImplementationProvider
TimeSpan _pooledConnectionLifetime
Func< SocketsHttpPlaintextStreamFilterContext, CancellationToken, ValueTask< Stream > > _plaintextStreamFilter
ICredentials _credentials
TimeSpan _pooledConnectionIdleTimeout
int _maxConnectionsPerServer
Func< SocketsHttpConnectionContext, CancellationToken, ValueTask< Stream > > _connectCallback
Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
override void Trace(string message, [CallerMemberName] string memberName=null)
static HttpMethod Connect
static readonly HttpTelemetry Log
static byte[] EncodeLiteralHeaderFieldWithStaticNameReferenceToArray(int index)
static async ValueTask EstablishSocksTunnelAsync(Stream stream, string host, int port, Uri proxyUri, ICredentials proxyCredentials, bool async, CancellationToken cancellationToken)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static QuicImplementationProvider Default
static Exception SetCurrentStackTrace(Exception source)
static string net_http_proxy_tunnel_returned_failure_status_code
static string net_http_connect_timedout
static string Format(string resourceFormat, object p1)
static string net_http_exception_during_plaintext_filter
static string net_http_client_execution_error
static string net_http_requested_version_cannot_establish
static string net_http_null_from_connect_callback
static string net_http_http2_connection_not_established
static string net_http_null_from_plaintext_filter
static string net_http_request_aborted
static string net_ssl_http2_requires_tls12
static string net_http_requested_version_server_refused
static bool IsFlowSuppressed()
static AsyncFlowControl SuppressFlow()
static void RestoreFlow()
static TaskScheduler Default
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
static Task Run(Action action)
static Task Delay(TimeSpan delay)
static readonly TimeSpan InfiniteTimeSpan
bool Dispose(WaitHandle notifyObject)
bool Change(int dueTime, int period)
static bool Read(ref bool location)
static Microsoft.Extensions.Internal.ValueStopwatch StartNew()
TaskCompletionSourceWithCancellation< T > Waiter
HttpRequestMessage Request
Queue< QueueItem > _queue
bool TryPeekNextRequest([NotNullWhen(true)] out HttpRequestMessage request)
bool TryDequeueNextRequest(T connection)
TaskCompletionSourceWithCancellation< T > EnqueueRequest(HttpRequestMessage request)
bool TryFailNextRequest(Exception e)
static readonly SslApplicationProtocol Http2
void AppendLiteral(string value)
void AppendFormatted(ReadOnlySpan< char > value)
static readonly TimeSpan Zero
static TimeSpan FromTicks(long value)