public Response <DownstreamRoute> FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod, IOcelotConfiguration configuration) { upstreamUrlPath = upstreamUrlPath.SetLastCharacterAs('/'); var applicableReRoutes = configuration.ReRoutes.Where(r => r.UpstreamHttpMethod.Count == 0 || r.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(upstreamHttpMethod.ToLower())); foreach (var reRoute in applicableReRoutes) { if (upstreamUrlPath == reRoute.UpstreamTemplatePattern) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } var urlMatch = _urlMatcher.Match(upstreamUrlPath, reRoute.UpstreamTemplatePattern); if (urlMatch.Data.Match) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } } return(new ErrorResponse <DownstreamRoute>(new List <Error> { new UnableToFindDownstreamRouteError() })); }
public async Task <Response <DownstreamRoute> > FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod) { var configuration = await _configProvider.Get(); var applicableReRoutes = configuration.Data.ReRoutes.Where(r => string.Equals(r.UpstreamHttpMethod.Method, upstreamHttpMethod, StringComparison.CurrentCultureIgnoreCase)); foreach (var reRoute in applicableReRoutes) { if (upstreamUrlPath == reRoute.UpstreamTemplatePattern) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } var urlMatch = _urlMatcher.Match(upstreamUrlPath, reRoute.UpstreamTemplatePattern); if (urlMatch.Data.Match) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } } return(new ErrorResponse <DownstreamRoute>(new List <Error> { new UnableToFindDownstreamRouteError() })); }
private void WhenIFindTheUrlVariableNamesAndValues() { _result = _finder.Find(_downstreamUrlPath, _downstreamPathTemplate); }