Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SendWithVersionDetectionAndRetryAsync()

async ValueTask< HttpResponseMessage > System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync ( HttpRequestMessage request,
bool async,
bool doRequestAuth,
CancellationToken cancellationToken )
inline

Definition at line 783 of file HttpConnectionPool.cs.

784 {
785 int retryCount = 0;
786 while (true)
787 {
788 try
789 {
790 HttpResponseMessage response = null;
791 if (IsHttp3Supported() && _http3Enabled && (request.Version.Major >= 3 || (request.VersionPolicy == HttpVersionPolicy.RequestVersionOrHigher && IsSecure)))
792 {
794 }
795 if (response == null)
796 {
797 if (request.Version.Major >= 3 && request.VersionPolicy != 0)
798 {
800 }
801 if (_http2Enabled && (request.Version.Major >= 2 || (request.VersionPolicy == HttpVersionPolicy.RequestVersionOrHigher && IsSecure)) && (request.VersionPolicy != 0 || IsSecure))
802 {
804 if (http2Connection != null)
805 {
807 }
808 }
809 if (response == null)
810 {
811 if (request.Version.Major >= 2 && request.VersionPolicy != 0)
812 {
814 }
815 HttpConnection connection = await GetHttp11ConnectionAsync(request, async, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
816 connection.Acquire();
817 try
818 {
820 }
821 finally
822 {
823 connection.Release();
824 }
825 }
826 }
828 return response;
829 }
830 catch (HttpRequestException ex) when (ex.AllowRetry == RequestRetryType.RetryOnConnectionFailure)
831 {
832 if (retryCount == 3)
833 {
834 if (System.Net.NetEventSource.Log.IsEnabled())
835 {
836 Trace($"MaxConnectionFailureRetries limit of {3} hit. Retryable request will not be retried. Exception: {ex}", "SendWithVersionDetectionAndRetryAsync");
837 }
838 throw;
839 }
840 retryCount++;
841 if (System.Net.NetEventSource.Log.IsEnabled())
842 {
843 Trace($"Retry attempt {retryCount} after connection failure. Connection exception: {ex}", "SendWithVersionDetectionAndRetryAsync");
844 }
845 }
846 catch (HttpRequestException ex2) when (ex2.AllowRetry == RequestRetryType.RetryOnLowerHttpVersion)
847 {
848 if (request.VersionPolicy != 0)
849 {
850 throw new HttpRequestException(System.SR.Format(System.SR.net_http_requested_version_server_refused, request.Version, request.VersionPolicy), ex2);
851 }
852 if (System.Net.NetEventSource.Log.IsEnabled())
853 {
854 Trace($"Retrying request because server requested version fallback: {ex2}", "SendWithVersionDetectionAndRetryAsync");
855 }
856 request.Version = HttpVersion.Version11;
857 }
858 catch (HttpRequestException ex3) when (ex3.AllowRetry == RequestRetryType.RetryOnStreamLimitReached)
859 {
860 if (System.Net.NetEventSource.Log.IsEnabled())
861 {
862 Trace($"Retrying request on another HTTP/2 connection after active streams limit is reached on existing one: {ex3}", "SendWithVersionDetectionAndRetryAsync");
863 }
864 }
865 }
866 }
static void ThrowGetVersionException(HttpRequestMessage request, int desiredVersion)
void ProcessAltSvc(HttpResponseMessage response)
async ValueTask< HttpResponseMessage > TrySendUsingHttp3Async(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
Task< HttpResponseMessage > SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)
async ValueTask< Http2Connection > GetHttp2ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
void Trace(string message, [CallerMemberName] string memberName=null)
async ValueTask< HttpConnection > GetHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
static readonly System.Net.NetEventSource Log
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_http_requested_version_server_refused
Definition SR.cs:202
Definition SR.cs:7
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226

References System.Net.Http.HttpConnectionPool._http2Enabled, System.Net.Http.HttpConnectionPool._http3Enabled, System.Net.Http.HttpConnection.Acquire(), System.cancellationToken, System.Threading.Tasks.Task< TResult >.ConfigureAwait(), System.SR.Format(), System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(), System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(), System.Net.Http.HttpConnectionPool.IsHttp3Supported(), System.Net.Http.HttpConnectionPool.IsSecure, System.Net.NetEventSource.Log, System.SR.net_http_requested_version_server_refused, System.Net.Http.HttpConnectionPool.ProcessAltSvc(), System.Net.Http.HttpConnection.Release(), System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(), System.Net.Http.HttpConnectionPool.ThrowGetVersionException(), System.Net.Http.HttpConnectionPool.Trace(), System.Net.Http.HttpConnectionPool.TrySendUsingHttp3Async(), and System.Net.HttpVersion.Version11.

Referenced by System.Net.Http.HttpConnectionPool.SendWithProxyAuthAsync().