Пример #1
0
        private void UpdateDownstreamHostAndPorts(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.DownstreamHostAndPorts == null)
            {
                route.RemoveAllDownstreamHostAndPorts();
                return;
            }

            foreach (var host in input.DownstreamHostAndPorts)
            {
                var existing = route.FindDownstreamHostAndPort(host.Host, host.Port.Value);
                if (existing == null)
                {
                    route.AddDownstreamHostAndPort(host.Host, host.Port.Value);
                }
            }

            //TODO Copied with ToList to avoid modification of the collection in the for loop
            foreach (var host in route.DownstreamHostAndPorts.ToList())
            {
                if (!input.DownstreamHostAndPorts.Any(c => host.Equals(route.GlobalConfigurationId, route.Name, c.Host, c.Port.Value)))
                {
                    route.RemoveDownstreamHostAndPort(host.Host, host.Port);
                }
            }
        }
Пример #2
0
        public virtual void AddRoutes(string name,
                                      string upstreamPathTemplate,
                                      string upstreamHost,
                                      string downstreamHttpMethod,
                                      string downstreamPathTemplate,
                                      string downstreamScheme,
                                      string key = null,
                                      string serviceNamespace   = null,
                                      string serviceName        = null,
                                      bool routeIsCaseSensitive = false,
                                      string requestIdKey       = null,
                                      bool dangerousAcceptAnyServerCertificateValidator = false,
                                      int timeout  = 5000,
                                      int sort     = 100,
                                      int priority = 1,
                                      List <string> upstreamHttpMethods = null,
                                      Dictionary <string, int> downstreamHostAndPorts = null)
        {
            var route = new OcelotRoute(
                Id,
                name,
                upstreamHost,
                upstreamPathTemplate,
                downstreamHttpMethod,
                downstreamPathTemplate,
                downstreamScheme,
                key,
                serviceNamespace,
                serviceName,
                routeIsCaseSensitive,
                requestIdKey,
                dangerousAcceptAnyServerCertificateValidator,
                timeout,
                sort,
                priority
                );

            if (upstreamHttpMethods != null)
            {
                foreach (var item in upstreamHttpMethods)
                {
                    route.AddUpstreamHttpMethod(item);
                }
            }
            if (downstreamHostAndPorts != null)
            {
                foreach (var item in downstreamHostAndPorts)
                {
                    route.AddDownstreamHostAndPort(item.Key, item.Value);
                }
            }

            Routes.Add(route);
        }
Пример #3
0
        public List <RouteDownstreamHostAndPort> Resolve(OcelotRouteDto source, OcelotRoute destination, List <RouteDownstreamHostAndPort> destMember, ResolutionContext context)
        {
            if (source == null || source.DownstreamHostAndPorts == null)
            {
                return(null);
            }

            foreach (var item in source.DownstreamHostAndPorts)
            {
                destination.AddDownstreamHostAndPort(item.Host, item.Port.Value);
            }

            return(destination.DownstreamHostAndPorts);
        }