Skip to content

Commit af32927

Browse files
author
Matt Mason
committed
Don't throw if no content for webhook
1 parent c1e7465 commit af32927

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/WebJobs.Script/Description/Node/NodeFunctionInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private Dictionary<string, object> CreateScriptExecutionContext(object input, Da
331331
if (httpBinding != null &&
332332
!string.IsNullOrEmpty(httpBinding.WebHookType))
333333
{
334-
input = requestObject["body"];
334+
requestObject.TryGetValue("body", out input);
335335
}
336336

337337
// make the entire request object available as well

test/WebJobs.Script.Tests/NodeEndToEndTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,29 @@ public async Task WebHookTrigger_GenericJson()
648648
Assert.Equal(string.Format("WebHook processed successfully! {0}", testData), body);
649649
}
650650

651+
[Fact]
652+
public async Task WebHookTrigger_NoContent()
653+
{
654+
HttpRequestMessage request = new HttpRequestMessage
655+
{
656+
RequestUri = new Uri(string.Format("http://localhost/api/webhooktrigger?code=1388a6b0d05eca2237f10e4a4641260b0a08f3a5")),
657+
Method = HttpMethod.Post,
658+
};
659+
request.SetConfiguration(new HttpConfiguration());
660+
661+
Dictionary<string, object> arguments = new Dictionary<string, object>
662+
{
663+
{ "payload", request }
664+
};
665+
await Fixture.Host.CallAsync("WebHookTrigger", arguments);
666+
667+
HttpResponseMessage response = (HttpResponseMessage)request.Properties[ScriptConstants.AzureFunctionsHttpResponseKey];
668+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
669+
670+
string body = await response.Content.ReadAsStringAsync();
671+
Assert.Equal(string.Format("No content"), body);
672+
}
673+
651674
[Fact]
652675
public async Task TimerTrigger()
653676
{
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = function (context, payload) {
22
context.log('Webhook was triggered!');
3-
context.res = {
4-
body: 'WebHook processed successfully! ' + payload.a
5-
};
6-
context.done();
3+
if (payload) {
4+
context.res.send('WebHook processed successfully! ' + payload.a);
5+
} else {
6+
context.res.send('No content');
7+
}
78
}

0 commit comments

Comments
 (0)