forked from NetCoreStack/Proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyUriDefinition.cs
More file actions
49 lines (41 loc) · 1.49 KB
/
Copy pathProxyUriDefinition.cs
File metadata and controls
49 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
namespace NetCoreStack.Proxy
{
public class ProxyUriDefinition
{
public static readonly IDictionary<string, string> TemplateCache =
new Dictionary<string, string>();
public UriBuilder UriBuilder { get; set; }
public bool HasParameter { get; private set; }
public ProxyUriDefinition(UriBuilder uriBuilder)
{
UriBuilder = uriBuilder;
}
public void ResolveTemplate(ProxyMethodDescriptor methodDescriptor, string route, string template)
{
var path = UriBuilder.Path ?? string.Empty;
if (methodDescriptor.RouteTemplate != null)
{
if (methodDescriptor.RouteTemplate.Parameters.Count > 0)
{
HasParameter = true;
var key = route + "/" + template;
if (TemplateCache.TryGetValue(key, out string tmpl))
{
path += $"{route}/{tmpl}";
UriBuilder.Path = path;
return;
}
tmpl = string.Join("/", methodDescriptor.TemplateKeys);
TemplateCache.Add(key, tmpl);
path += $"{route}/{tmpl}";
UriBuilder.Path = path;
return;
}
}
path += $"{route}/{template}";
UriBuilder.Path = path;
}
}
}