#419 Incorrect routing when UpstreamHost is specified and UpstreamHttpMethod is empty (#420)

This commit is contained in:
David Nissimoff 2018-06-20 14:41:00 -07:00 committed by Tom Pallister
parent e636cefdb1
commit fffc4c8d3c
2 changed files with 15 additions and 1 deletions

View File

@ -49,7 +49,8 @@ namespace Ocelot.DownstreamRouteFinder.Finder
private bool RouteIsApplicableToThisRequest(ReRoute reRoute, string httpMethod, string upstreamHost) private bool RouteIsApplicableToThisRequest(ReRoute reRoute, string httpMethod, string upstreamHost)
{ {
return reRoute.UpstreamHttpMethod.Count == 0 || reRoute.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(httpMethod.ToLower()) && !(!string.IsNullOrEmpty(reRoute.UpstreamHost) && reRoute.UpstreamHost != upstreamHost); return (reRoute.UpstreamHttpMethod.Count == 0 || reRoute.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(httpMethod.ToLower())) &&
(string.IsNullOrEmpty(reRoute.UpstreamHost) || reRoute.UpstreamHost == upstreamHost);
} }
private DownstreamRoute GetPlaceholderNamesAndValues(string path, ReRoute reRoute) private DownstreamRoute GetPlaceholderNamesAndValues(string path, ReRoute reRoute)

View File

@ -583,6 +583,19 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
.WithUpstreamHttpMethod(new List<string> { "Get" }) .WithUpstreamHttpMethod(new List<string> { "Get" })
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1)) .WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
.WithUpstreamHost("MATCH") .WithUpstreamHost("MATCH")
.Build(),
new ReRouteBuilder()
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("someDownstreamPath")
.WithUpstreamPathTemplate("someUpstreamPath")
.WithUpstreamHttpMethod(new List<string> { }) // empty list of methods
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
.WithUpstreamHost("MATCH")
.Build())
.WithUpstreamPathTemplate("someUpstreamPath")
.WithUpstreamHttpMethod(new List<string> { }) // empty list of methods
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
.WithUpstreamHost("MATCH")
.Build() .Build()
}, string.Empty, serviceProviderConfig }, string.Empty, serviceProviderConfig
)) ))