mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
Adds the posibility of use final paths in the reroutes of configuration.json file.
Adds a unit test method to test the functionality.
This commit is contained in:
parent
8d31b40c21
commit
b8ee43c737
@ -19,7 +19,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
|
||||
{
|
||||
var variableName = GetPlaceholderVariableName(upstreamUrlPathTemplate, counterForTemplate);
|
||||
|
||||
var variableValue = GetPlaceholderVariableValue(upstreamUrlPath, counterForUrl);
|
||||
var variableValue = GetPlaceholderVariableValue(upstreamUrlPathTemplate, variableName, upstreamUrlPath, counterForUrl);
|
||||
|
||||
var templateVariableNameAndValue = new UrlPathPlaceholderNameAndValue(variableName, variableValue);
|
||||
|
||||
@ -40,11 +40,11 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
|
||||
return new OkResponse<List<UrlPathPlaceholderNameAndValue>>(templateKeysAndValues);
|
||||
}
|
||||
|
||||
private string GetPlaceholderVariableValue(string urlPath, int counterForUrl)
|
||||
private string GetPlaceholderVariableValue(string urlPathTemplate, string variableName, string urlPath, int counterForUrl)
|
||||
{
|
||||
var positionOfNextSlash = urlPath.IndexOf('/', counterForUrl);
|
||||
|
||||
if(positionOfNextSlash == -1)
|
||||
if (positionOfNextSlash == -1 || urlPathTemplate.Trim('/').EndsWith(variableName))
|
||||
{
|
||||
positionOfNextSlash = urlPath.Length;
|
||||
}
|
||||
|
@ -140,6 +140,21 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_place_holder_to_final_url_path()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{finalUrlPath}", "product/products/categories/"),
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/categories/"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("api/{finalUrlPath}/"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheTemplatesVariablesAre(List<UrlPathPlaceholderNameAndValue> expectedResults)
|
||||
{
|
||||
foreach (var expectedResult in expectedResults)
|
||||
|
Loading…
x
Reference in New Issue
Block a user