mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	Add the possibility of set mutiple verbs in the UpstreamHttpMethod property.
Add UnitTests and AcceptanceTests to try this feature.
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Builder
 | 
			
		||||
{
 | 
			
		||||
@@ -11,7 +12,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
        private string _downstreamPathTemplate;
 | 
			
		||||
        private string _upstreamTemplate;
 | 
			
		||||
        private string _upstreamTemplatePattern;
 | 
			
		||||
        private string _upstreamHttpMethod;
 | 
			
		||||
        private List<HttpMethod> _upstreamHttpMethod;
 | 
			
		||||
        private bool _isAuthenticated;
 | 
			
		||||
        private List<ClaimToThing> _configHeaderExtractorProperties;
 | 
			
		||||
        private List<ClaimToThing> _claimToClaims;
 | 
			
		||||
@@ -68,7 +69,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
        }
 | 
			
		||||
        public ReRouteBuilder WithUpstreamHttpMethod(string input)
 | 
			
		||||
        {
 | 
			
		||||
            _upstreamHttpMethod = input;
 | 
			
		||||
            _upstreamHttpMethod = string.IsNullOrWhiteSpace(input) ? new List<HttpMethod>() : input.Split(',').Select(x => new HttpMethod(x.Trim())).ToList();
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
        public ReRouteBuilder WithIsAuthenticated(bool input)
 | 
			
		||||
@@ -180,7 +181,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
            return new ReRoute(
 | 
			
		||||
                new PathTemplate(_downstreamPathTemplate), 
 | 
			
		||||
                new PathTemplate(_upstreamTemplate), 
 | 
			
		||||
                new HttpMethod(_upstreamHttpMethod), 
 | 
			
		||||
                _upstreamHttpMethod, 
 | 
			
		||||
                _upstreamTemplatePattern, 
 | 
			
		||||
                _isAuthenticated, 
 | 
			
		||||
                _authenticationOptions,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ namespace Ocelot.Configuration
 | 
			
		||||
    {
 | 
			
		||||
        public ReRoute(PathTemplate downstreamPathTemplate, 
 | 
			
		||||
            PathTemplate upstreamPathTemplate, 
 | 
			
		||||
            HttpMethod upstreamHttpMethod, 
 | 
			
		||||
            List<HttpMethod> upstreamHttpMethod, 
 | 
			
		||||
            string upstreamTemplatePattern, 
 | 
			
		||||
            bool isAuthenticated, 
 | 
			
		||||
            AuthenticationOptions authenticationOptions, 
 | 
			
		||||
@@ -64,7 +64,7 @@ namespace Ocelot.Configuration
 | 
			
		||||
        public PathTemplate DownstreamPathTemplate { get; private set; }
 | 
			
		||||
        public PathTemplate UpstreamPathTemplate { get; private set; }
 | 
			
		||||
        public string UpstreamTemplatePattern { get; private set; }
 | 
			
		||||
        public HttpMethod UpstreamHttpMethod { get; private set; }
 | 
			
		||||
        public List<HttpMethod> UpstreamHttpMethod { get; private set; }
 | 
			
		||||
        public bool IsAuthenticated { get; private set; }
 | 
			
		||||
        public bool IsAuthorised { get; private set; }
 | 
			
		||||
        public AuthenticationOptions AuthenticationOptions { get; private set; }
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ namespace Ocelot.DownstreamRouteFinder.Finder
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = await _configProvider.Get();
 | 
			
		||||
 | 
			
		||||
            var applicableReRoutes = configuration.Data.ReRoutes.Where(r => string.Equals(r.UpstreamHttpMethod.Method.ToLower(), upstreamHttpMethod.ToLower(), StringComparison.CurrentCultureIgnoreCase));
 | 
			
		||||
            var applicableReRoutes = configuration.Data.ReRoutes.Where(r => r.UpstreamHttpMethod.Count == 0 || r.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(upstreamHttpMethod.ToLower()));
 | 
			
		||||
 | 
			
		||||
            foreach (var reRoute in applicableReRoutes)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user