|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
6 |
| -using System.IO; |
7 |
| -using System.Net; |
8 |
| -using System.Net.Http; |
| 6 | +using System.Linq; |
9 | 7 | using System.Threading;
|
10 | 8 | using System.Threading.Tasks;
|
11 |
| -using System.Web.Http.Dependencies; |
| 9 | +using Microsoft.AspNetCore.Http; |
12 | 10 | using Microsoft.Azure.AppService.Proxy.Client.Contract;
|
13 | 11 | using Microsoft.Azure.WebJobs.Extensions.Http;
|
14 |
| -using Microsoft.Azure.WebJobs.Script.Description; |
15 | 12 | using Microsoft.Azure.WebJobs.Script.WebHost;
|
16 |
| -using Microsoft.Azure.WebJobs.Script.WebHost.Controllers; |
17 |
| -using Microsoft.Azure.WebJobs.Script.WebHost.WebHooks; |
18 | 13 |
|
19 | 14 | namespace Microsoft.Azure.WebJobs.Script.Host
|
20 | 15 | {
|
21 | 16 | public class ProxyFunctionExecutor : IFuncExecutor
|
22 | 17 | {
|
23 | 18 | private readonly WebScriptHostManager _scriptHostManager;
|
24 |
| - private readonly ISecretManager _secretManager; |
25 |
| - private WebHookReceiverManager _webHookReceiverManager; |
| 19 | + private readonly IWebJobsRouteHandler _routeHandler; |
26 | 20 |
|
27 |
| - internal ProxyFunctionExecutor(WebScriptHostManager scriptHostManager, WebHookReceiverManager webHookReceiverManager, ISecretManager secretManager) |
| 21 | + internal ProxyFunctionExecutor(WebScriptHostManager scriptHostManager, IWebJobsRouteHandler routeHandler) |
28 | 22 | {
|
29 | 23 | _scriptHostManager = scriptHostManager;
|
30 |
| - _webHookReceiverManager = webHookReceiverManager; |
31 |
| - _secretManager = secretManager; |
| 24 | + _routeHandler = routeHandler; |
32 | 25 | }
|
33 | 26 |
|
34 |
| - public async Task ExecuteFuncAsync(string funcName, Dictionary<string, object> arguments, CancellationToken cancellationToken) |
| 27 | + public async Task ExecuteFuncAsync(string functionName, Dictionary<string, object> arguments, CancellationToken cancellationToken) |
35 | 28 | {
|
36 |
| - HttpRequestMessage request = arguments[ScriptConstants.AzureFunctionsHttpRequestKey] as HttpRequestMessage; |
37 |
| - var function = _scriptHostManager.GetHttpFunctionOrNull(request); |
| 29 | + var request = arguments[ScriptConstants.AzureFunctionsHttpRequestKey] as HttpRequest; |
| 30 | + var function = _scriptHostManager.Instance.Functions.FirstOrDefault(f => string.Equals(f.Name, functionName)); |
38 | 31 |
|
39 |
| - var functionRequestInvoker = new FunctionRequestInvoker(function, _secretManager); |
40 |
| - var response = await functionRequestInvoker.PreprocessRequestAsync(request); |
41 |
| - |
42 |
| - if (response != null) |
43 |
| - { |
44 |
| - request.Properties[ScriptConstants.AzureFunctionsHttpResponseKey] = response; |
45 |
| - return; |
46 |
| - } |
47 |
| - |
48 |
| - Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> processRequestHandler = async (req, ct) => |
49 |
| - { |
50 |
| - return await functionRequestInvoker.ProcessRequestAsync(req, ct, _scriptHostManager, _webHookReceiverManager); |
51 |
| - }; |
52 |
| - |
53 |
| - var resp = await _scriptHostManager.HttpRequestManager.ProcessRequestAsync(request, processRequestHandler, cancellationToken); |
54 |
| - request.Properties[ScriptConstants.AzureFunctionsHttpResponseKey] = resp; |
55 |
| - return; |
| 32 | + await _routeHandler.InvokeAsync(request.HttpContext, functionName); |
56 | 33 | }
|
57 | 34 | }
|
58 | 35 | }
|
0 commit comments