Exemplo n.º 1
0
 private void StartContentBuffering(HttpRequestMessage request, CancellationTokenSource cancellationTokenSource, TaskCompletionSource<HttpResponseMessage> tcs, HttpResponseMessage response)
 {
     response.Content.LoadIntoBufferAsync(TransportConfiguration.MaxResponseContentBufferSize).ContinueWithStandard(delegate (Task contentTask) {
         try
         {
             bool flag = cancellationTokenSource.Token.IsCancellationRequested;
             if (contentTask.IsFaulted)
             {
                 response.Dispose();
                 if (flag && (contentTask.Exception.GetBaseException() is HttpRequestException))
                 {
                     SetTaskCanceled(request, cancellationTokenSource, tcs);
                 }
                 else
                 {
                     SetTaskFaulted(request, cancellationTokenSource, tcs, contentTask.Exception.GetBaseException());
                 }
             }
             else if (contentTask.IsCanceled)
             {
                 response.Dispose();
                 SetTaskCanceled(request, cancellationTokenSource, tcs);
             }
             else
             {
                 SetTaskCompleted(request, cancellationTokenSource, tcs, response);
             }
         }
         catch (Exception exception)
         {
             response.Dispose();
             tcs.TrySetException(exception);
             if (Logging.On)
             {
                 Logging.Exception(Logging.Http, this, "SendAsync", exception);
             }
         }
     });
 }
Exemplo n.º 2
0
 private void SetTaskCompleted(HttpRequestMessage request, CancellationTokenSource cancellationTokenSource, TaskCompletionSource<HttpResponseMessage> tcs, HttpResponseMessage response)
 {
     //if (Logging.On)
     //{
     //    Logging.PrintInfo(Logging.Http, this, string.Format(CultureInfo.InvariantCulture, SR.net_http_client_send_completed, new object[] { Logging.GetObjectLogHash(request), Logging.GetObjectLogHash(response), response }));
     //}
     tcs.TrySetResult(response);
     DisposeCancellationToken(cancellationTokenSource);
 }