Пример #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);
        }
Пример #2
0
 protected internal override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     if (DiagnosticsHandler.IsEnabled())
     {
         return(_diagnosticsPipeline.SendAsync(request, cancellationToken));
     }
     return(_curlHandler.SendAsync(request, cancellationToken));
 }
Пример #3
0
        protected internal override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                         CancellationToken cancellationToken)
        {
            // Get current value of WindowsProxyUsePolicy.  Only call its WinHttpHandler
            // property setter if the value needs to change.
            var oldProxyUsePolicy = _winHttpHandler.WindowsProxyUsePolicy;

            if (_useProxy)
            {
                if (_winHttpHandler.Proxy == null)
                {
                    if (oldProxyUsePolicy != WindowsProxyUsePolicy.UseWinInetProxy)
                    {
                        _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
                    }
                }
                else
                {
                    if (oldProxyUsePolicy != WindowsProxyUsePolicy.UseCustomProxy)
                    {
                        _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy;
                    }
                }
            }
            else
            {
                if (oldProxyUsePolicy != WindowsProxyUsePolicy.DoNotUseProxy)
                {
                    _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.DoNotUseProxy;
                }
            }

            if (DiagnosticsHandler.IsEnabled())
            {
                return(_diagnosticsPipeline.SendAsync(request, cancellationToken));
            }
            return(_winHttpHandler.SendAsync(request, cancellationToken));
        }
Пример #4
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);
        }