Пример #1
0
        public FeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, ICacheProvider cacheProvider = null, ILoggerFactory loggerFactory = null)
        {
            FeignOptions = feignOptions;
            _globalFeignClientPipeline    = FeignOptions.FeignClientPipeline as GlobalFeignClientPipeline;
            _serviceIdFeignClientPipeline = _globalFeignClientPipeline?.GetServicePipeline(ServiceId);
            _serviceFeignClientPipeline   = _globalFeignClientPipeline?.GetServicePipeline <TService>();
            _logger = loggerFactory?.CreateLogger(typeof(FeignClientHttpProxy <TService>));
            ServiceDiscoveryHttpClientHandler <TService> serviceDiscoveryHttpClientHandler = new ServiceDiscoveryHttpClientHandler <TService>(this, serviceDiscovery, cacheProvider, _logger);

            if (FeignOptions.AutomaticDecompression.HasValue)
            {
                serviceDiscoveryHttpClientHandler.AutomaticDecompression = feignOptions.AutomaticDecompression.Value;
            }
            if (FeignOptions.UseCookies.HasValue)
            {
                serviceDiscoveryHttpClientHandler.UseCookies = FeignOptions.UseCookies.Value;
            }
            //serviceDiscoveryHttpClientHandler.ShouldResolveService = string.IsNullOrWhiteSpace(Url);
            serviceDiscoveryHttpClientHandler.ShouldResolveService = Url == null;
            serviceDiscoveryHttpClientHandler.AllowAutoRedirect    = false;
            HttpClient = new FeignHttpClient(new FeignDelegatingHandler(serviceDiscoveryHttpClientHandler));
            string baseUrl = serviceDiscoveryHttpClientHandler.ShouldResolveService ? ServiceId ?? "" : Url;

            BaseUrl = BuildBaseUrl(baseUrl);

            InitializingEventArgs <TService> initializingEventArgs = new InitializingEventArgs <TService>(this);

            initializingEventArgs.HttpClient = HttpClient;
            OnInitializing(initializingEventArgs);
            HttpClient = initializingEventArgs.HttpClient;
            if (HttpClient == null)
            {
                throw new ArgumentNullException(nameof(HttpClient));
            }
        }
Пример #2
0
        public FeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, ICacheProvider cacheProvider = null, ILoggerFactory loggerFactory = null)
        {
            FeignOptions = feignOptions;
            _globalFeignClientPipeline    = FeignOptions.FeignClientPipeline as GlobalFeignClientPipeline;
            _serviceIdFeignClientPipeline = _globalFeignClientPipeline?.GetServicePipeline(ServiceId);
            _serviceFeignClientPipeline   = _globalFeignClientPipeline?.GetServicePipeline <TService>();
            _logger = loggerFactory?.CreateLogger(typeof(FeignClientHttpProxy <TService>));
            ServiceDiscoveryHttpClientHandler <TService> serviceDiscoveryHttpClientHandler = new ServiceDiscoveryHttpClientHandler <TService>(this, serviceDiscovery, cacheProvider, _logger);

            if (FeignOptions.AutomaticDecompression.HasValue)
            {
                serviceDiscoveryHttpClientHandler.AutomaticDecompression = feignOptions.AutomaticDecompression.Value;
            }
            //serviceDiscoveryHttpClientHandler.ShouldResolveService = string.IsNullOrWhiteSpace(Url);
            serviceDiscoveryHttpClientHandler.ShouldResolveService = Url == null;
            serviceDiscoveryHttpClientHandler.AllowAutoRedirect    = false;
            HttpClient = new FeignHttpClient(new FeignDelegatingHandler(serviceDiscoveryHttpClientHandler));
            string baseUrl = serviceDiscoveryHttpClientHandler.ShouldResolveService ? ServiceId ?? "" : Url;

            if (!baseUrl.StartsWith("http") && baseUrl != "")
            {
                baseUrl = $"http://{baseUrl}";
            }
            if (!string.IsNullOrWhiteSpace(BaseUri))
            {
                if (baseUrl.EndsWith("/"))
                {
                    baseUrl = baseUrl.TrimEnd('/');
                }
                if (BaseUri.StartsWith("/"))
                {
                    baseUrl += BaseUri;
                }
                else
                {
                    baseUrl += "/" + BaseUri;
                }
            }
            if (baseUrl.EndsWith("/"))
            {
                baseUrl = baseUrl.TrimEnd('/');
            }
            BaseUrl = baseUrl;

            InitializingEventArgs <TService> initializingEventArgs = new InitializingEventArgs <TService>(this);

            initializingEventArgs.HttpClient = HttpClient;
            OnInitializing(initializingEventArgs);
            HttpClient = initializingEventArgs.HttpClient;
            if (HttpClient == null)
            {
                throw new ArgumentNullException(nameof(HttpClient));
            }
        }
Пример #3
0
 public PollyFeignHttpClient(FeignHttpClient feignHttpClient, IAsyncPolicy asyncPolicy) : base(feignHttpClient.Handler)
 {
 }