Пример #1
0
        public IHttpClient Create(DownstreamContext request)
        {
            _cacheKey = GetCacheKey(request);

            var httpClient = _cacheHandlers.Get(_cacheKey);

            if (httpClient != null)
            {
                return(httpClient);
            }

            _httpclientHandler = new HttpClientHandler
            {
                AllowAutoRedirect = request.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
                UseCookies        = request.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
                CookieContainer   = new CookieContainer()
            };

            var timeout = request.DownstreamReRoute.QosOptionsOptions.TimeoutValue == 0
                ? _defaultTimeout
                : TimeSpan.FromMilliseconds(request.DownstreamReRoute.QosOptionsOptions.TimeoutValue);

            _httpClient = new HttpClient(CreateHttpMessageHandler(_httpclientHandler, request.DownstreamReRoute))
            {
                Timeout = timeout
            };

            _client = new HttpClientWrapper(_httpClient);

            return(_client);
        }
        public IHttpClient Create(DownstreamContext context)
        {
            _cacheKey = GetCacheKey(context);

            var httpClient = _cacheHandlers.Get(_cacheKey);

            if (httpClient != null)
            {
                _client = httpClient;
                return(httpClient);
            }

            var handler = CreateHandler(context);

            if (context.DownstreamReRoute.DangerousAcceptAnyServerCertificateValidator)
            {
                handler.ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => true;

                _logger
                .LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {context.DownstreamReRoute.DownstreamPathTemplate}");
            }

            var timeout = context.DownstreamReRoute.QosOptions.TimeoutValue == 0
                ? _defaultTimeout
                : TimeSpan.FromMilliseconds(context.DownstreamReRoute.QosOptions.TimeoutValue);

            _httpClient = new HttpClient(CreateHttpMessageHandler(handler, context.DownstreamReRoute))
            {
                Timeout = timeout
            };

            _client = new HttpClientWrapper(_httpClient);

            return(_client);
        }
Пример #3
0
        private IHttpClient GetHttpClient(HttpRequestMessage httpRequestMessage)
        {
            var httpClientCacheKey = GetHttpClientCacheKey(httpRequestMessage);
            var httpClient         = _httpClientCache.Get(httpClientCacheKey, _circuitBreakerConfig);

            return(httpClient);
        }
        private IHttpClient GetHttpClient(string cacheKey, IHttpClientBuilder builder, bool useCookieContainer, bool allowAutoRedirect)
        {
            var httpClient = _cacheHandlers.Get(cacheKey);

            if (httpClient == null)
            {
                httpClient = builder.Create(useCookieContainer, allowAutoRedirect);
            }
            return(httpClient);
        }
Пример #5
0
        private IHttpClient GetHttpClient(string cacheKey, IHttpClientBuilder builder)
        {
            var httpClient = _cacheHandlers.Get(cacheKey);

            if (httpClient == null)
            {
                httpClient = builder.Create();
            }
            return(httpClient);
        }
        private IHttpClient GetHttpClient(string cacheKey, IHttpClientBuilder builder, DownstreamContext request)
        {
            var httpClient = _cacheHandlers.Get(cacheKey);

            if (httpClient == null)
            {
                httpClient = builder.Create(request.DownstreamReRoute);
            }

            return(httpClient);
        }
Пример #7
0
        public IHttpClient Create(DownstreamContext context)
        {
            _cacheKey = GetCacheKey(context);

            var httpClient = _cacheHandlers.Get(_cacheKey);

            if (httpClient != null)
            {
                return(httpClient);
            }
            bool useCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer;
            HttpClientHandler httpclientHandler;

            // Dont' create the CookieContainer if UseCookies is not set ot the HttpClient will complain
            // under .Net Full Framework
            if (useCookies)
            {
                httpclientHandler = new HttpClientHandler
                {
                    AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
                    UseCookies        = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
                    CookieContainer   = new CookieContainer()
                };
            }
            else
            {
                httpclientHandler = new HttpClientHandler
                {
                    AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
                    UseCookies        = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
                };
            }

            if (context.DownstreamReRoute.DangerousAcceptAnyServerCertificateValidator)
            {
                httpclientHandler.ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => true;

                _logger
                .LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {context.DownstreamReRoute.DownstreamPathTemplate}");
            }

            var timeout = context.DownstreamReRoute.QosOptions.TimeoutValue == 0
                ? _defaultTimeout
                : TimeSpan.FromMilliseconds(context.DownstreamReRoute.QosOptions.TimeoutValue);

            _httpClient = new HttpClient(CreateHttpMessageHandler(httpclientHandler, context.DownstreamReRoute))
            {
                Timeout = timeout
            };

            _client = new HttpClientWrapper(_httpClient);

            return(_client);
        }
Пример #8
0
        private IHttpClient GetHttpClient(Request.Request request)
        {
            var builder    = new HttpClientBuilder();
            var cacheKey   = GetCacheKey(request, builder);
            var httpClient = _cacheHandlers.Get(cacheKey);

            if (httpClient == null)
            {
                httpClient = builder.Create();
            }
            _cacheHandlers.Set(cacheKey, httpClient, TimeSpan.FromHours(6));
            return(httpClient);
        }
Пример #9
0
        public IHttpClient Create(DownstreamContext context)
        {
            _cacheKey = GetCacheKey(context);

            var httpClient = _cacheHandlers.Get(_cacheKey);

            if (httpClient != null)
            {
                return(httpClient);
            }

            var httpclientHandler = new HttpClientHandler
            {
                AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
                UseCookies        = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
                CookieContainer   = new CookieContainer()
            };

            if (context.DownstreamReRoute.DangerousAcceptAnyServerCertificateValidator)
            {
                httpclientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

                _logger
                .LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {context.DownstreamReRoute.DownstreamPathTemplate}");
            }

            var timeout = context.DownstreamReRoute.QosOptionsOptions.TimeoutValue == 0
                ? _defaultTimeout
                : TimeSpan.FromMilliseconds(context.DownstreamReRoute.QosOptionsOptions.TimeoutValue);

            _httpClient = new HttpClient(CreateHttpMessageHandler(httpclientHandler, context.DownstreamReRoute))
            {
                Timeout = timeout
            };

            _client = new HttpClientWrapper(_httpClient);

            return(_client);
        }
Пример #10
0
        public IHttpClient Create(DownstreamContext request)
        {
            _cacheKey = GetCacheKey(request);

            var httpClient = _cacheHandlers.Get(_cacheKey);

            if (httpClient != null)
            {
                return(httpClient);
            }

            _httpclientHandler = new HttpClientHandler
            {
                AllowAutoRedirect = request.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
                UseCookies        = request.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
                CookieContainer   = new CookieContainer()
            };

            _httpClient = new HttpClient(CreateHttpMessageHandler(_httpclientHandler, request.DownstreamReRoute));

            _client = new HttpClientWrapper(_httpClient);

            return(_client);
        }
Пример #11
0
 /// <summary>
 /// Creates a SolidHttpClient
 /// </summary>
 /// <returns>SolidHttpClient</returns>
 public SolidHttpClient Create()
 {
     return(CreateSolidHttpClient(_cache.Get()));
 }