Esempio 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);
        }
Esempio n. 2
0
        public HttpClientHandler()
        {
            if (UseManagedHandler)
            {
                _managedHandler     = new ManagedHandler();
                _diagnosticsHandler = new DiagnosticsHandler(_managedHandler);
            }
            else
            {
                _winHttpHandler     = new WinHttpHandler();
                _diagnosticsHandler = new DiagnosticsHandler(_winHttpHandler);

                // Adjust defaults to match current .NET Desktop HttpClientHandler (based on HWR stack).
                AllowAutoRedirect      = true;
                AutomaticDecompression = HttpHandlerDefaults.DefaultAutomaticDecompression;
                UseProxy        = true;
                UseCookies      = true;
                CookieContainer = new CookieContainer();
                _winHttpHandler.DefaultProxyCredentials = null;
                _winHttpHandler.ServerCredentials       = null;

                // The existing .NET Desktop HttpClientHandler based on the HWR stack uses only WinINet registry
                // settings for the proxy.  This also includes supporting the "Automatic Detect a proxy" using
                // WPAD protocol and PAC file. So, for app-compat, we will do the same for the default proxy setting.
                _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
                _winHttpHandler.Proxy = null;

                // Since the granular WinHttpHandler timeout properties are not exposed via the HttpClientHandler API,
                // we need to set them to infinite and allow the HttpClient.Timeout property to have precedence.
                _winHttpHandler.ReceiveHeadersTimeout = Timeout.InfiniteTimeSpan;
                _winHttpHandler.ReceiveDataTimeout    = Timeout.InfiniteTimeSpan;
                _winHttpHandler.SendTimeout           = Timeout.InfiniteTimeSpan;
            }
        }
Esempio n. 3
0
 protected internal override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     if (DiagnosticsHandler.IsEnabled())
     {
         return(_diagnosticsPipeline.SendAsync(request, cancellationToken));
     }
     return(_curlHandler.SendAsync(request, cancellationToken));
 }
Esempio n. 4
0
 public HttpClientHandler()
 {
     _underlyingHandler = new HttpHandlerType();
     if (DiagnosticsHandler.IsGloballyEnabled())
     {
         _diagnosticsHandler = new DiagnosticsHandler(_underlyingHandler);
     }
     ClientCertificateOptions = ClientCertificateOption.Manual;
 }
Esempio n. 5
0
        public HttpClientHandler()
        {
#if TARGETS_BROWSER
            _underlyingHandler = new BrowserHttpHandler();
#else
            _underlyingHandler = new SocketsHttpHandler();
#endif
            _diagnosticsHandler      = new DiagnosticsHandler(_underlyingHandler);
            ClientCertificateOptions = ClientCertificateOption.Manual;
        }
Esempio n. 6
0
        public HttpClientHandler()
        {
#if TARGET_BROWSER
            _underlyingHandler = new BrowserHttpHandler();
#else
            _underlyingHandler = new SocketsHttpHandler();
#endif
            if (DiagnosticsHandler.IsGloballyEnabled())
            {
                _diagnosticsHandler = new DiagnosticsHandler(_underlyingHandler);
            }
            ClientCertificateOptions = ClientCertificateOption.Manual;
        }
 public HttpClientHandler()
 {
     if (UseManagedHandler)
     {
         _managedHandler     = new ManagedHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_managedHandler);
     }
     else
     {
         _curlHandler        = new CurlHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_curlHandler);
     }
 }
 private HttpClientHandler(bool useSocketsHttpHandler) // used by parameterless ctor and as hook for testing
 {
     if (useSocketsHttpHandler)
     {
         _socketsHttpHandler = new SocketsHttpHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_socketsHttpHandler);
     }
     else
     {
         _curlHandler        = new CurlHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_curlHandler);
     }
 }
Esempio n. 9
0
        public HttpClientHandler()
        {
            _underlyingHandler = new HttpHandlerType();

#if TARGET_BROWSER
            Handler = _underlyingHandler;
            if (DiagnosticsHandler.IsGloballyEnabled())
            {
                Handler = new DiagnosticsHandler(Handler, DistributedContextPropagator.Current);
            }
#endif

            ClientCertificateOptions = ClientCertificateOption.Manual;
        }
Esempio n. 10
0
 public HttpClientHandler()
 {
     if (UseManagedHandler)
     {
         _managedHandler = new ManagedHandler()
         {
             SslOptions = new SslClientAuthenticationOptions()
         };
         _diagnosticsHandler = new DiagnosticsHandler(_managedHandler);
     }
     else
     {
         _curlHandler        = new CurlHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_curlHandler);
     }
 }
Esempio n. 11
0
        protected internal override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                         CancellationToken cancellationToken)
        {
            if (DiagnosticsHandler.IsGloballyEnabled() && _diagnosticsHandler != null)
            {
                return(_diagnosticsHandler !.SendAsync(request, cancellationToken));
            }

            if (IsNativeHandlerEnabled)
            {
                return(_nativeHandler !.SendAsync(request, cancellationToken));
            }
            else
            {
                return(_socketHandler !.SendAsync(request, cancellationToken));
            }
        }
        public HttpClientHandler()
        {
            HttpMessageHandler handler;

            if (IsNativeHandlerEnabled)
            {
                _nativeHandler = CreateNativeHandler();
                handler        = _nativeHandler;
            }
            else
            {
                _socketHandler = new SocketsHttpHandler();
                handler        = _socketHandler;
            }

            if (DiagnosticsHandler.IsGloballyEnabled())
            {
                _diagnosticsHandler = new DiagnosticsHandler(handler, DistributedContextPropagator.Current);
            }
        }
Esempio n. 13
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));
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
 public HttpClientHandler()
 {
     _curlHandler         = new CurlHandler();
     _diagnosticsPipeline = new DiagnosticsHandler(_curlHandler);
 }
Esempio n. 16
0
 public HttpClientHandler()
 {
     _socketsHttpHandler      = new SocketsHttpHandler();
     _diagnosticsHandler      = new DiagnosticsHandler(_socketsHttpHandler);
     ClientCertificateOptions = ClientCertificateOption.Manual;
 }