Add the possibility of set mutiple verbs in the UpstreamHttpMethod property.

Add UnitTests and AcceptanceTests to try this feature.
This commit is contained in:
Juan Carlos Santana Herrera
2017-05-04 10:56:16 +01:00
parent be3a2fb6ed
commit e91da1ac23
5 changed files with 152 additions and 6 deletions

View File

@ -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,

View File

@ -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; }

View File

@ -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)
{