Ocelot/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs
2018-03-03 13:48:30 +00:00

25 lines
929 B
C#

using System.Collections.Generic;
using System.Text;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Responses;
using Ocelot.Values;
namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer
{
public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer
{
public Response<DownstreamPath> Replace(PathTemplate downstreamPathTemplate, List<PlaceholderNameAndValue> urlPathPlaceholderNameAndValues)
{
var downstreamPath = new StringBuilder();
downstreamPath.Append(downstreamPathTemplate.Value);
foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues)
{
downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value);
}
return new OkResponse<DownstreamPath>(new DownstreamPath(downstreamPath.ToString()));
}
}
}