mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 17:48:15 +08:00
changes to add new feature to url routing (#186)
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
@ -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()}");
|
||||
|
Reference in New Issue
Block a user