@@ -22,7 +22,6 @@ public class ProxyFunctionExecutor : IFuncExecutor
2222 {
2323 private readonly WebScriptHostManager _scriptHostManager ;
2424 private readonly ISecretManager _secretManager ;
25- private readonly string _httpPrefix ;
2625
2726 private WebHookReceiverManager _webHookReceiverManager ;
2827
@@ -31,82 +30,16 @@ internal ProxyFunctionExecutor(WebScriptHostManager scriptHostManager, WebHookRe
3130 _scriptHostManager = scriptHostManager ;
3231 _webHookReceiverManager = webHookReceiverManager ;
3332 _secretManager = secretManager ;
34-
35- _httpPrefix = HttpExtensionConstants . DefaultRoutePrefix ;
36-
37- if ( _scriptHostManager . Instance != null )
38- {
39- var json = _scriptHostManager . Instance . ScriptConfig . HostConfig . HostConfigMetadata ;
40-
41- if ( json != null && json [ "http" ] != null && json [ "http" ] [ "routePrefix" ] != null )
42- {
43- _httpPrefix = json [ "http" ] [ "routePrefix" ] . ToString ( ) . Trim ( new char [ ] { '/' } ) ;
44- }
45- }
4633 }
4734
4835 public async Task ExecuteFuncAsync ( string funcName , Dictionary < string , object > arguments , CancellationToken cancellationToken )
4936 {
5037 HttpRequestMessage request = arguments [ ScriptConstants . AzureFunctionsHttpRequestKey ] as HttpRequestMessage ;
5138
5239 FunctionDescriptor function = null ;
53- var path = request . RequestUri . AbsolutePath . Trim ( new char [ ] { '/' } ) ;
54-
55- if ( path . StartsWith ( _httpPrefix ) )
56- {
57- path = path . Remove ( 0 , _httpPrefix . Length ) ;
58- }
5940
60- path = path . Trim ( new char [ ] { '/' } ) ;
61-
62- // This is a call to the local function app, before handing the route to asp.net to pick the FunctionDescriptor the following will be run:
63- // 1. If the request maps to a local http trigger function name then that function will be picked.
64- // 2. Else if the request maps to a custom route of a local http trigger function then that function will be picked
65- // 3. Otherwise the request will be given to asp.net to pick the appropriate route.
66- foreach ( var route in _scriptHostManager . Routes )
67- {
68- var func = ( FunctionDescriptor ) route . DataTokens [ ScriptConstants . AzureFunctionsHttpFunctionKey ] ;
69- if ( ! func . Metadata . IsProxy )
70- {
71- if ( path . Equals ( func . Metadata . Name , StringComparison . OrdinalIgnoreCase ) )
72- {
73- function = func ;
74- break ;
75- }
76- else
77- {
78- foreach ( var binding in func . InputBindings )
79- {
80- if ( binding . Metadata . IsTrigger )
81- {
82- string functionRoute = null ;
83- var jsonContent = binding . Metadata . Raw ;
84- if ( jsonContent != null && jsonContent [ "route" ] != null )
85- {
86- functionRoute = jsonContent [ "route" ] . ToString ( ) ;
87- }
88-
89- // BUG: Known issue, This does not work on dynamic routes like products/{category:alpha}/{id:int?}
90- if ( ! string . IsNullOrEmpty ( functionRoute ) && path . Equals ( functionRoute , StringComparison . OrdinalIgnoreCase ) )
91- {
92- function = func ;
93- break ;
94- }
95- }
96- }
97-
98- if ( function != null )
99- {
100- break ;
101- }
102- }
103- }
104- }
105-
106- if ( function == null )
107- {
108- function = _scriptHostManager . GetHttpFunctionOrNull ( request ) ;
109- }
41+ // This is a call to the local function app from proxy, in this scenario first match will be against local http triggers then rest of the proxies to avoid infinite redirect for * mappings in proxies.
42+ function = _scriptHostManager . GetHttpFunctionOrNull ( request , proxyRoutesFirst : false ) ;
11043
11144 var functionRequestInvoker = new FunctionRequestInvoker ( function , _secretManager ) ;
11245 var response = await functionRequestInvoker . PreprocessRequestAsync ( request ) ;
0 commit comments