changes to add new feature to url routing (#186)

This commit is contained in:
Tom Pallister
2018-01-02 18:49:22 +00:00
committed by GitHub
parent f082f7318a
commit 931a115ffa
4 changed files with 106 additions and 3 deletions

View File

@ -9,6 +9,7 @@ namespace Ocelot.Configuration.Creator
private const string RegExMatchEndString = "$";
private const string RegExIgnoreCase = "(?i)";
private const string RegExForwardSlashOnly = "^/$";
private const string RegExForwardSlashAndOnePlaceHolder = "^/.*";
public string Create(FileReRoute reRoute)
{
@ -22,8 +23,13 @@ namespace Ocelot.Configuration.Creator
{
var postitionOfPlaceHolderClosingBracket = upstreamTemplate.IndexOf('}', i);
var difference = postitionOfPlaceHolderClosingBracket - i + 1;
var variableName = upstreamTemplate.Substring(i, difference);
placeholders.Add(variableName);
var placeHolderName = upstreamTemplate.Substring(i, difference);
placeholders.Add(placeHolderName);
if(ForwardSlashAndOnePlaceHolder(upstreamTemplate, placeholders, postitionOfPlaceHolderClosingBracket))
{
return RegExForwardSlashAndOnePlaceHolder;
}
}
}
@ -49,6 +55,16 @@ namespace Ocelot.Configuration.Creator
return route;
}
private bool ForwardSlashAndOnePlaceHolder(string upstreamTemplate, List<string> placeholders, int postitionOfPlaceHolderClosingBracket)
{
if(upstreamTemplate.Substring(0, 2) == "/{" && placeholders.Count == 1 && upstreamTemplate.Length == postitionOfPlaceHolderClosingBracket + 1)
{
return true;
}
return false;
}
private bool IsPlaceHolder(string upstreamTemplate, int i)
{

View File

@ -38,6 +38,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
//todo make this getting config its own middleware one day?
var configuration = await _configProvider.Get();
if(configuration.IsError)
{
_logger.LogError($"{MiddlewareName} setting pipeline errors. IOcelotConfigurationProvider returned {configuration.Errors.ToErrorString()}");