private void UpdateUpstreamHttpMethods(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.UpstreamHttpMethods == null)
            {
                route.RemoveAllUpstreamHttpMethods();
                return;
            }

            foreach (var method in input.UpstreamHttpMethods)
            {
                var existing = route.FindUpstreamHttpMethod(method);
                if (existing == null)
                {
                    route.AddUpstreamHttpMethod(method);
                }
            }

            //TODO Copied with ToList to avoid modification of the collection in the for loop
            foreach (var method in route.UpstreamHttpMethods.ToList())
            {
                if (!input.UpstreamHttpMethods.Any(c => method.Equals(route.GlobalConfigurationId, route.Name, c)))
                {
                    route.RemoveUpstreamHttpMethod(method.Method);
                }
            }
        }
Beispiel #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);
        }
Beispiel #3
0
        public List <RouteUpstreamHttpMethod> Resolve(OcelotRouteDto source, OcelotRoute destination, List <RouteUpstreamHttpMethod> destMember, ResolutionContext context)
        {
            if (source == null || source.UpstreamHttpMethods == null)
            {
                return(null);
            }

            foreach (var item in source.UpstreamHttpMethods)
            {
                destination.AddUpstreamHttpMethod(item);
            }

            return(destination.UpstreamHttpMethods);
        }