|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
| 6 | +using System.Collections.ObjectModel; |
6 | 7 | using System.Dynamic;
|
7 | 8 | using System.Globalization;
|
8 | 9 | using System.IO;
|
9 | 10 | using System.Net;
|
| 11 | +using System.Reflection.Emit; |
| 12 | +using System.Threading.Tasks; |
10 | 13 | using Microsoft.AspNetCore.Http;
|
11 | 14 | using Microsoft.AspNetCore.Mvc;
|
12 | 15 | using Microsoft.AspNetCore.Mvc.WebApiCompatShim;
|
|
16 | 19 |
|
17 | 20 | namespace Microsoft.Azure.WebJobs.Script.Binding
|
18 | 21 | {
|
19 |
| - public class HttpBinding |
| 22 | + public class HttpBinding : FunctionBinding |
20 | 23 | {
|
| 24 | + public HttpBinding(ScriptHostConfiguration config, BindingMetadata metadata, FileAccess access) |
| 25 | + : base(config, metadata, access) |
| 26 | + { |
| 27 | + } |
| 28 | + |
| 29 | + public override Collection<CustomAttributeBuilder> GetCustomAttributes(Type parameterType) |
| 30 | + { |
| 31 | + return null; |
| 32 | + } |
| 33 | + |
| 34 | + public override Task BindAsync(BindingContext context) |
| 35 | + { |
| 36 | + HttpRequest request = (HttpRequest)context.TriggerValue; |
| 37 | + |
| 38 | + object content = context.Value; |
| 39 | + if (content is Stream) |
| 40 | + { |
| 41 | + // for script language functions (e.g. PowerShell, BAT, etc.) the value |
| 42 | + // will be a Stream which we need to convert to string |
| 43 | + ConvertStreamToValue((Stream)content, DataType.String, ref content); |
| 44 | + } |
| 45 | + |
| 46 | + IActionResult response = CreateResult(request, content); |
| 47 | + request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey] = response; |
| 48 | + |
| 49 | + return Task.CompletedTask; |
| 50 | + } |
| 51 | + |
21 | 52 | internal static IActionResult CreateResult(HttpRequest request, object content)
|
22 | 53 | {
|
23 | 54 | string stringContent = content as string;
|
|
0 commit comments