more simplification is that a word

This commit is contained in:
TomPallister
2016-09-07 20:40:56 +01:00
parent 15d7cafa1c
commit 71b7e7743e
18 changed files with 56 additions and 262 deletions

View File

@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Ocelot.Library.Infrastructure.UrlTemplateRepository;
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
namespace Ocelot.Library.Middleware
@ -14,40 +13,31 @@ namespace Ocelot.Library.Middleware
{
private readonly RequestDelegate _next;
private readonly IUrlPathToUrlTemplateMatcher _urlMatcher;
private readonly IUrlTemplateMapRepository _urlTemplateMapRepository;
private readonly IDownstreamUrlTemplateVariableReplacer _urlReplacer;
private readonly IOptions<Configuration> _optionsAccessor;
private readonly IOptions<Configuration> _configuration;
public ProxyMiddleware(RequestDelegate next,
IUrlPathToUrlTemplateMatcher urlMatcher,
IUrlTemplateMapRepository urlPathRepository,
IDownstreamUrlTemplateVariableReplacer urlReplacer, IOptions<Configuration> optionsAccessor)
IDownstreamUrlTemplateVariableReplacer urlReplacer, IOptions<Configuration> configuration)
{
_next = next;
_urlMatcher = urlMatcher;
_urlTemplateMapRepository = urlPathRepository;
_urlReplacer = urlReplacer;
_optionsAccessor = optionsAccessor;
_configuration = configuration;
}
public async Task Invoke(HttpContext context)
{
var downstreamUrlPath = context.Request.Path.ToString();
var upstreamUrlTemplates = _urlTemplateMapRepository.All;
{
var upstreamUrlPath = context.Request.Path.ToString();
UrlMatch urlMatch = null;
string downstreamUrlTemplate = string.Empty;
foreach (var template in upstreamUrlTemplates.Data)
foreach (var template in _configuration.Value.ReRoutes)
{
urlMatch = _urlMatcher.Match(downstreamUrlPath, template.DownstreamUrlTemplate);
urlMatch = _urlMatcher.Match(upstreamUrlPath, template.UpstreamTemplate);
if (urlMatch.Match)
{
downstreamUrlTemplate = template.DownstreamUrlTemplate;
break;
}
}
@ -58,7 +48,7 @@ namespace Ocelot.Library.Middleware
return;
}
var downstreamUrl = _urlReplacer.ReplaceTemplateVariable(downstreamUrlTemplate, urlMatch);
var downstreamUrl = _urlReplacer.ReplaceTemplateVariable(urlMatch);
//make a http request to this endpoint...maybe bring in a library