SendAsync() protected method

protected SendAsync ( HttpRequestMessage request, CancellationToken cancel ) : Task
request HttpRequestMessage
cancel System.Threading.CancellationToken
return Task
Exemplo n.º 1
0
        protected internal override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                               CancellationToken cancellationToken)
        {
            CheckDisposed();
            SetOperationStarted();

            HttpResponseMessage response;

            try
            {
                await ConfigureRequest(request).ConfigureAwait(false);

                Task <HttpResponseMessage> responseTask = DiagnosticsHandler.IsEnabled() ?
                                                          _diagnosticsPipeline.SendAsync(request, cancellationToken) :
                                                          _handlerToFilter.SendAsync(request, cancellationToken);

                response = await responseTask.ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // Convert back to the expected exception type
                throw new HttpRequestException(SR.net_http_client_execution_error, ex);
            }

            ProcessResponse(response);
            return(response);
        }
Exemplo n.º 2
0
        protected internal override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                               CancellationToken cancellationToken)
        {
            CheckDisposed();
            SetOperationStarted();

            HttpResponseMessage response;

            try
            {
                if (string.Equals(request.Method.Method, HttpMethod.Trace.Method, StringComparison.OrdinalIgnoreCase))
                {
                    // https://github.com/dotnet/corefx/issues/22161
                    throw new PlatformNotSupportedException(SR.Format(CultureInfo.InvariantCulture,
                                                                      SR.net_http_httpmethod_notsupported_error, request.Method.Method));
                }

                await ConfigureRequest(request).ConfigureAwait(false);

                Task <HttpResponseMessage> responseTask = DiagnosticsHandler.IsEnabled() ?
                                                          _diagnosticsPipeline.SendAsync(request, cancellationToken) :
                                                          _handlerToFilter.SendAsync(request, cancellationToken);

                response = await responseTask.ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // Convert back to the expected exception type.
                throw new HttpRequestException(SR.net_http_client_execution_error, ex);
            }

            return(response);
        }