|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
6 |
| -using System.Collections.ObjectModel; |
7 | 6 | using System.Dynamic;
|
8 | 7 | using System.Globalization;
|
9 | 8 | using System.IO;
|
10 |
| -using System.Linq; |
11 | 9 | using System.Net;
|
12 |
| -using System.Reflection.Emit; |
13 |
| -using System.Threading.Tasks; |
14 | 10 | using Microsoft.AspNetCore.Http;
|
15 | 11 | using Microsoft.AspNetCore.Mvc;
|
16 | 12 | using Microsoft.AspNetCore.Mvc.WebApiCompatShim;
|
17 | 13 | using Microsoft.Azure.WebJobs.Script.Description;
|
18 |
| -using Microsoft.Net.Http.Headers; |
19 | 14 | using Newtonsoft.Json;
|
20 | 15 | using Newtonsoft.Json.Linq;
|
21 | 16 |
|
22 | 17 | namespace Microsoft.Azure.WebJobs.Script.Binding
|
23 | 18 | {
|
24 |
| - public class HttpBinding : FunctionBinding |
| 19 | + public class HttpBinding |
25 | 20 | {
|
26 |
| - public HttpBinding(ScriptHostConfiguration config, BindingMetadata metadata, FileAccess access) |
27 |
| - : base(config, metadata, access) |
28 |
| - { |
29 |
| - } |
30 |
| - |
31 |
| - public override Collection<CustomAttributeBuilder> GetCustomAttributes(Type parameterType) |
32 |
| - { |
33 |
| - return null; |
34 |
| - } |
35 |
| - |
36 |
| - public override Task BindAsync(BindingContext context) |
37 |
| - { |
38 |
| - HttpRequest request = (HttpRequest)context.TriggerValue; |
39 |
| - |
40 |
| - object content = context.Value; |
41 |
| - if (content is Stream) |
42 |
| - { |
43 |
| - // for script language functions (e.g. PowerShell, BAT, etc.) the value |
44 |
| - // will be a Stream which we need to convert to string |
45 |
| - ConvertStreamToValue((Stream)content, DataType.String, ref content); |
46 |
| - } |
47 |
| - |
48 |
| - IActionResult response = CreateResult(request, content); |
49 |
| - request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey] = response; |
50 |
| - |
51 |
| - return Task.CompletedTask; |
52 |
| - } |
53 |
| - |
54 | 21 | internal static IActionResult CreateResult(HttpRequest request, object content)
|
55 | 22 | {
|
56 | 23 | string stringContent = content as string;
|
@@ -188,17 +155,31 @@ internal static void SetResponse(HttpRequest request, object result)
|
188 | 155 | IActionResult actionResult = result as IActionResult;
|
189 | 156 | if (actionResult == null)
|
190 | 157 | {
|
191 |
| - var objectResult = new ObjectResult(result); |
192 |
| - |
193 |
| - if (result is System.Net.Http.HttpResponseMessage) |
| 158 | + if (result is Stream) |
194 | 159 | {
|
195 |
| - // To maintain backwards compatibility, if the type returned is an |
196 |
| - // instance of an HttpResponseMessage, add the appropriate formatter to |
197 |
| - // handle the response |
198 |
| - objectResult.Formatters.Add(new HttpResponseMessageOutputFormatter()); |
| 160 | + // for script language functions (e.g. PowerShell, BAT, etc.) the value |
| 161 | + // will be a Stream which we need to convert to string |
| 162 | + FunctionBinding.ConvertStreamToValue((Stream)result, DataType.String, ref result); |
| 163 | + actionResult = CreateResult(request, result); |
199 | 164 | }
|
| 165 | + else if (result is JObject) |
| 166 | + { |
| 167 | + actionResult = CreateResult(request, result); |
| 168 | + } |
| 169 | + else |
| 170 | + { |
| 171 | + var objectResult = new ObjectResult(result); |
200 | 172 |
|
201 |
| - actionResult = objectResult; |
| 173 | + if (result is System.Net.Http.HttpResponseMessage) |
| 174 | + { |
| 175 | + // To maintain backwards compatibility, if the type returned is an |
| 176 | + // instance of an HttpResponseMessage, add the appropriate formatter to |
| 177 | + // handle the response |
| 178 | + objectResult.Formatters.Add(new HttpResponseMessageOutputFormatter()); |
| 179 | + } |
| 180 | + |
| 181 | + actionResult = objectResult; |
| 182 | + } |
202 | 183 | }
|
203 | 184 |
|
204 | 185 | request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey] = actionResult;
|
|
0 commit comments