diff --git a/sample/WebHook-Generic-CSharp/run.csx b/sample/WebHook-Generic-CSharp/run.csx index 9369229910..b54ee4a14e 100644 --- a/sample/WebHook-Generic-CSharp/run.csx +++ b/sample/WebHook-Generic-CSharp/run.csx @@ -4,13 +4,18 @@ using System; using System.Net; using System.Threading.Tasks; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; public static async Task Run(HttpRequestMessage req, TraceWriter log) { string json = await req.Content.ReadAsStringAsync(); Payload payload = JsonConvert.DeserializeObject(json); - return req.CreateResponse(HttpStatusCode.OK, $"Value: {payload.Value}"); + JObject body = new JObject() + { + { "result", $"Value: {payload.Value}" } + }; + return req.CreateResponse(HttpStatusCode.OK, body, "application/json"); } public class Payload diff --git a/sample/WebHook-Generic/index.js b/sample/WebHook-Generic/index.js index b9058a4934..fba5f21d5d 100644 --- a/sample/WebHook-Generic/index.js +++ b/sample/WebHook-Generic/index.js @@ -1,7 +1,9 @@ module.exports = function (context, data) { context.log('Webhook was triggered!'); context.res = { - body: 'WebHook processed successfully! ' + data.a + body: { + result: 'Value: ' + data.value + } }; context.done(); } \ No newline at end of file diff --git a/src/WebJobs.Script/Binding/HttpBinding.cs b/src/WebJobs.Script/Binding/HttpBinding.cs index 07aef41d81..8e0bb9787b 100644 --- a/src/WebJobs.Script/Binding/HttpBinding.cs +++ b/src/WebJobs.Script/Binding/HttpBinding.cs @@ -70,6 +70,14 @@ public override async Task BindAsync(BindingContext context) response = new HttpResponseMessage(statusCode); response.Content = new StringContent(body); + // we default the Content-Type here, but we override below with any + // Content-Type header the user might have set themselves + if (Utility.IsJson(body)) + { + response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + } + + // apply any user specified headers JObject headers = (JObject)jsonObject["headers"]; if (headers != null) { diff --git a/src/WebJobs.Script/Description/NodeFunctionInvoker.cs b/src/WebJobs.Script/Description/NodeFunctionInvoker.cs index 6e29048b4d..b8ec23ed60 100644 --- a/src/WebJobs.Script/Description/NodeFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/NodeFunctionInvoker.cs @@ -395,7 +395,7 @@ private bool TryDeserializeJsonObject(string json, out Dictionary GetBindingData(object value, IBinder // if the input value is a JSON string, extract additional // binding data from it string json = value as string; - if (!string.IsNullOrEmpty(json) && IsJson(json)) + if (!string.IsNullOrEmpty(json) && Utility.IsJson(json)) { // parse the object skipping any nested objects (binding data // only includes top level properties) @@ -155,13 +155,6 @@ protected static void ApplyAmbientBindingData(IBinderEx binder, IDictionary