mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 05:28:15 +08:00
working state
This commit is contained in:
@ -0,0 +1,7 @@
|
||||
namespace Ocelot.Library.Infrastructure.Router.UrlPathMatcher
|
||||
{
|
||||
public interface IUrlPathToUrlPathTemplateMatcher
|
||||
{
|
||||
bool Match(string urlPath, string urlPathTemplate);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
namespace Ocelot.Library.Infrastructure.Router.UrlPathMatcher
|
||||
{
|
||||
public class UrlPathToUrlPathTemplateMatcher : IUrlPathToUrlPathTemplateMatcher
|
||||
{
|
||||
public bool Match(string urlPath, string urlPathTemplate)
|
||||
{
|
||||
urlPath = urlPath.ToLower();
|
||||
|
||||
urlPathTemplate = urlPathTemplate.ToLower();
|
||||
|
||||
int counterForUrl = 0;
|
||||
|
||||
for (int counterForTemplate = 0; counterForTemplate < urlPathTemplate.Length; counterForTemplate++)
|
||||
{
|
||||
if (CharactersDontMatch(urlPathTemplate[counterForTemplate], urlPath[counterForUrl]) && ContinueScanningUrl(counterForUrl,urlPath.Length))
|
||||
{
|
||||
if (IsPlaceholder(urlPathTemplate[counterForTemplate]))
|
||||
{
|
||||
counterForTemplate = GetNextCounterPosition(urlPathTemplate, counterForTemplate, '}');
|
||||
counterForUrl = GetNextCounterPosition(urlPath, counterForUrl, '/');
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
counterForUrl++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int GetNextCounterPosition(string urlTemplate, int counterForTemplate, char delimiter)
|
||||
{
|
||||
var closingPlaceHolderPositionOnTemplate = urlTemplate.IndexOf(delimiter, counterForTemplate);
|
||||
return closingPlaceHolderPositionOnTemplate + 1;
|
||||
}
|
||||
|
||||
private bool CharactersDontMatch(char characterOne, char characterTwo)
|
||||
{
|
||||
return characterOne != characterTwo;
|
||||
}
|
||||
|
||||
private bool ContinueScanningUrl(int counterForUrl, int urlLength)
|
||||
{
|
||||
return counterForUrl < urlLength;
|
||||
}
|
||||
|
||||
private bool IsPlaceholder(char character)
|
||||
{
|
||||
return character == '{';
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ namespace Ocelot
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
app.Run(async context =>
|
||||
|
Reference in New Issue
Block a user