System.Net.Http.OwinHttpMessageHandler.SendInternalAsync C# (CSharp) Méthode

SendInternalAsync() private méthode

private SendInternalAsync ( HttpRequestMessage request, CancellationToken cancellationToken ) : Task
request HttpRequestMessage
cancellationToken System.Threading.CancellationToken
Résultat Task
        private async Task<HttpResponseMessage> SendInternalAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (_useCookies)
            {
                var cookieHeader = _cookieContainer.GetCookieHeader(request.RequestUri);
                if (!string.IsNullOrEmpty(cookieHeader))
                {
                    request.Headers.Add("Cookie", cookieHeader);
                }
            }

            var state = new RequestState(request, cancellationToken);

            var requestContent = request.Content ?? new StreamContent(Stream.Null);
            var body = await requestContent.ReadAsStreamAsync().NotOnCapturedContext();
            if (body.CanSeek)
            {
                // This body may have been consumed before, rewind it.
                body.Seek(0, SeekOrigin.Begin);
            }
            state.OwinContext.Request.Body = body;
            var registration = cancellationToken.Register(state.Abort);

            // Async offload, don't let the test code block the caller.
            Task offload = Task.Run(async () =>
            {
                try
                {
                    await _appFunc(state.Environment).NotOnCapturedContext();
                    state.CompleteResponse();
                }
                catch (Exception ex)
                {
                    state.Abort(ex);
                }
                finally
                {
                    registration.Dispose();
                    state.Dispose();
                }
            }, cancellationToken);

            HttpResponseMessage response = await state.ResponseTask.NotOnCapturedContext();
            CheckSetCookie(request, response);
            return response;
        }