mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-07-31 08:35:58 +08:00
messing around with the proxy mdh the proxy middleware
This commit is contained in:
@ -2,13 +2,13 @@ namespace Ocelot.Library.Infrastructure.HostUrlRepository
|
||||
{
|
||||
public class HostUrlMap
|
||||
{
|
||||
public HostUrlMap(string downstreamHostUrl, string upstreamHostUrl)
|
||||
public HostUrlMap(string urlPathTemplate, string upstreamHostUrl)
|
||||
{
|
||||
DownstreamHostUrl = downstreamHostUrl;
|
||||
UrlPathTemplate = urlPathTemplate;
|
||||
UpstreamHostUrl = upstreamHostUrl;
|
||||
}
|
||||
|
||||
public string DownstreamHostUrl {get;private set;}
|
||||
public string UrlPathTemplate {get;private set;}
|
||||
public string UpstreamHostUrl {get;private set;}
|
||||
}
|
||||
}
|
@ -5,6 +5,6 @@ namespace Ocelot.Library.Infrastructure.HostUrlRepository
|
||||
public interface IHostUrlMapRepository
|
||||
{
|
||||
Response AddBaseUrlMap(HostUrlMap baseUrlMap);
|
||||
Response<HostUrlMap> GetBaseUrlMap(string downstreamUrl);
|
||||
Response<HostUrlMap> GetBaseUrlMap(string urlPathTemplate);
|
||||
}
|
||||
}
|
@ -12,23 +12,23 @@ namespace Ocelot.Library.Infrastructure.HostUrlRepository
|
||||
}
|
||||
public Response AddBaseUrlMap(HostUrlMap baseUrlMap)
|
||||
{
|
||||
if(_routes.ContainsKey(baseUrlMap.DownstreamHostUrl))
|
||||
if(_routes.ContainsKey(baseUrlMap.UrlPathTemplate))
|
||||
{
|
||||
return new ErrorResponse(new List<Error>(){new HostUrlMapKeyAlreadyExists()});
|
||||
}
|
||||
|
||||
_routes.Add(baseUrlMap.DownstreamHostUrl, baseUrlMap.UpstreamHostUrl);
|
||||
_routes.Add(baseUrlMap.UrlPathTemplate, baseUrlMap.UpstreamHostUrl);
|
||||
|
||||
return new OkResponse();
|
||||
}
|
||||
|
||||
public Response<HostUrlMap> GetBaseUrlMap(string downstreamUrl)
|
||||
public Response<HostUrlMap> GetBaseUrlMap(string urlPathTemplate)
|
||||
{
|
||||
string upstreamUrl = null;
|
||||
|
||||
if(_routes.TryGetValue(downstreamUrl, out upstreamUrl))
|
||||
if(_routes.TryGetValue(urlPathTemplate, out upstreamUrl))
|
||||
{
|
||||
return new OkResponse<HostUrlMap>(new HostUrlMap(downstreamUrl, upstreamUrl));
|
||||
return new OkResponse<HostUrlMap>(new HostUrlMap(urlPathTemplate, upstreamUrl));
|
||||
}
|
||||
|
||||
return new ErrorResponse<HostUrlMap>(new List<Error>(){new HostUrlMapKeyDoesNotExist()});
|
@ -4,12 +4,15 @@ namespace Ocelot.Library.Infrastructure.UrlPathMatcher
|
||||
{
|
||||
public class UrlPathMatch
|
||||
{
|
||||
public UrlPathMatch(bool match, List<TemplateVariableNameAndValue> templateVariableNameAndValues)
|
||||
public UrlPathMatch(bool match, List<TemplateVariableNameAndValue> templateVariableNameAndValues, string urlPathTemplate)
|
||||
{
|
||||
Match = match;
|
||||
TemplateVariableNameAndValues = templateVariableNameAndValues;
|
||||
UrlPathTemplate = urlPathTemplate;
|
||||
}
|
||||
public bool Match {get;private set;}
|
||||
public List<TemplateVariableNameAndValue> TemplateVariableNameAndValues {get;private set;}
|
||||
|
||||
public string UrlPathTemplate {get;private set;}
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ namespace Ocelot.Library.Infrastructure.UrlPathMatcher
|
||||
{
|
||||
public UrlPathMatch Match(string urlPath, string urlPathTemplate)
|
||||
{
|
||||
var urlPathTemplateCopy = urlPathTemplate;
|
||||
|
||||
var templateKeysAndValues = new List<TemplateVariableNameAndValue>();
|
||||
|
||||
urlPath = urlPath.ToLower();
|
||||
@ -37,12 +39,12 @@ namespace Ocelot.Library.Infrastructure.UrlPathMatcher
|
||||
}
|
||||
else
|
||||
{
|
||||
return new UrlPathMatch(false, templateKeysAndValues);
|
||||
return new UrlPathMatch(false, templateKeysAndValues, string.Empty);
|
||||
}
|
||||
}
|
||||
counterForUrl++;
|
||||
}
|
||||
return new UrlPathMatch(true, templateKeysAndValues);
|
||||
return new UrlPathMatch(true, templateKeysAndValues, urlPathTemplateCopy);
|
||||
}
|
||||
|
||||
private string GetPlaceholderVariableValue(string urlPath, int counterForUrl)
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlPathTemplateRepository
|
||||
@ -6,5 +7,6 @@ namespace Ocelot.Library.Infrastructure.UrlPathTemplateRepository
|
||||
{
|
||||
Response AddUrlPathTemplateMap(UrlPathTemplateMap urlPathMap);
|
||||
Response<UrlPathTemplateMap> GetUrlPathTemplateMap(string downstreamUrlPathTemplate);
|
||||
Response<List<UrlPathTemplateMap>> All { get; }
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.UrlPathTemplateRepository
|
||||
@ -11,6 +12,18 @@ namespace Ocelot.Library.Infrastructure.UrlPathTemplateRepository
|
||||
{
|
||||
_routes = new Dictionary<string,string>();
|
||||
}
|
||||
|
||||
public Response<List<UrlPathTemplateMap>> All
|
||||
{
|
||||
get
|
||||
{
|
||||
var routes = _routes
|
||||
.Select(r => new UrlPathTemplateMap(r.Key, r.Value))
|
||||
.ToList();
|
||||
return new OkResponse<List<UrlPathTemplateMap>>(routes);
|
||||
}
|
||||
}
|
||||
|
||||
public Response AddUrlPathTemplateMap(UrlPathTemplateMap urlPathMap)
|
||||
{
|
||||
if(_routes.ContainsKey(urlPathMap.DownstreamUrlPathTemplate))
|
||||
|
Reference in New Issue
Block a user