@@ -12,34 +12,62 @@ public DefaultProxyEndpointManager(RoundRobinManager roundRobinManager)
1212 RoundRobinManager = roundRobinManager ;
1313 }
1414
15- public ProxyUriDefinition CreateUriDefinition ( ProxyMethodDescriptor methodDescriptor , string route , string regionKey , string targetMethodName )
15+ private string ConcatRoute ( string route , string methodName )
1616 {
17- var uriBuilder = RoundRobinManager . RoundRobinUri ( regionKey ) ;
18- if ( uriBuilder == null )
17+ string path = string . Empty ;
18+ if ( string . IsNullOrEmpty ( route ) )
1919 {
20- throw new ArgumentNullException ( nameof ( uriBuilder ) ) ;
20+ path = methodName ;
21+ }
22+ else
23+ {
24+ path = $ "{ route } /{ methodName } ";
2125 }
2226
23- var uriDefinition = new ProxyUriDefinition ( uriBuilder ) ;
27+ return path ;
28+ }
2429
25- if ( ! string . IsNullOrEmpty ( route ) )
30+ private void ResolveTemplate ( UriBuilder uriBuilder , ProxyMethodDescriptor methodDescriptor , string route , string targetMethodName )
31+ {
32+ var path = uriBuilder . Path ?? string . Empty ;
33+ if ( methodDescriptor . RouteTemplate != null )
2634 {
27- if ( targetMethodName . ToLower ( ) == HttpMethod . Get . Method . ToLower ( ) )
35+ if ( methodDescriptor . RouteTemplate . Parameters . Count > 0 )
2836 {
29- var path = uriDefinition . UriBuilder . Path ?? string . Empty ;
30- path += $ "{ route } /";
31- uriDefinition . UriBuilder . Path = path ;
37+ var methodName = string . Join ( "/" , methodDescriptor . TemplateKeys ) ;
38+ path += ConcatRoute ( route , methodName ) ;
39+ uriBuilder . Path = path ;
40+ return ;
3241 }
33- else
34- {
35- if ( targetMethodName . StartsWith ( "/" ) )
36- targetMethodName = targetMethodName . Substring ( 1 ) ;
42+ }
3743
38- uriDefinition . ResolveTemplate ( methodDescriptor , route , targetMethodName ) ;
39- }
44+ path += ConcatRoute ( route , targetMethodName ) ;
45+ uriBuilder . Path = path ;
46+ }
47+
48+ public UriBuilder CreateUriBuilder ( ProxyMethodDescriptor methodDescriptor , string route , string regionKey , string targetMethodName )
49+ {
50+ var uriBuilder = RoundRobinManager . RoundRobinUri ( regionKey ) ;
51+ if ( uriBuilder == null )
52+ {
53+ throw new ArgumentNullException ( nameof ( uriBuilder ) ) ;
54+ }
55+
56+ if ( targetMethodName . ToLower ( ) == HttpMethod . Get . Method . ToLower ( ) )
57+ {
58+ var path = uriBuilder . Path ?? string . Empty ;
59+ path += string . IsNullOrEmpty ( route ) ? "" : $ "{ route } /";
60+ uriBuilder . Path = path ;
61+ }
62+ else
63+ {
64+ if ( targetMethodName . StartsWith ( "/" ) )
65+ targetMethodName = targetMethodName . Substring ( 1 ) ;
66+
67+ ResolveTemplate ( uriBuilder , methodDescriptor , route , targetMethodName ) ;
4068 }
4169
42- return uriDefinition ;
70+ return uriBuilder ;
4371 }
4472 }
4573}
0 commit comments