From 700ca5c85adbac315344e84c23e18c200d729807 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sat, 21 Dec 2019 12:19:15 -0500 Subject: [PATCH 1/3] added rawBody --- packages/nodes-base/nodes/Webhook.node.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index 8bb09d0c05..3ac8acc3a2 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -296,9 +296,10 @@ export class Webhook implements INodeType { body: this.getBodyData(), headers, query: this.getQueryData(), + // @ts-ignore + rawBody: req.rawBody, } ); - return { workflowData: [ this.helpers.returnJsonArray(returnData) From f1bb1f10f3aba55a5d5ed50fc25d8f53e43cb348 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sat, 21 Dec 2019 15:36:08 -0500 Subject: [PATCH 2/3] changes --- packages/nodes-base/nodes/Webhook.node.ts | 58 ++++++++++++++++++----- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index 3ac8acc3a2..da3ecd3cdb 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -119,7 +119,6 @@ export class Webhook implements INodeType { default: 'GET', description: 'The HTTP method to liste to.', }, - { displayName: 'Path', name: 'path', @@ -205,7 +204,6 @@ export class Webhook implements INodeType { }, description: 'Name of the binary property to return', }, - { displayName: 'Options', name: 'options', @@ -238,15 +236,45 @@ export class Webhook implements INodeType { default: 'data', description: 'Name of the property to return the data of instead of the whole JSON.', }, + { + displayName: 'Raw Body', + name: 'rawBody', + type: 'boolean', + default: false, + description: 'Raw body (binary)', + }, + ], + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + displayOptions: { + show: { + responseMode: [ + 'onReceived', + ], + }, + }, + placeholder: 'Add Option', + default: {}, + options: [ + { + displayName: 'Raw Body', + name: 'rawBody', + type: 'boolean', + default: false, + description: 'Raw body (binary)', + }, ], }, - ], }; async webhook(this: IWebhookFunctions): Promise { const authentication = this.getNodeParameter('authentication', 0) as string; + const options = this.getNodeParameter('options', 0) as string; const req = this.getRequestObject(); const resp = this.getResponseObject(); const headers = this.getHeaderData(); @@ -288,21 +316,27 @@ export class Webhook implements INodeType { return authorizationError(resp, realm, 403); } } - - const returnData: IDataObject[] = []; - - returnData.push( - { + const response = { + json: { body: this.getBodyData(), headers, query: this.getQueryData(), + }, + }; + // @ts-ignore + if (options.rawBody) { + // @ts-ignore + response.binary = { // @ts-ignore - rawBody: req.rawBody, - } - ); + data: req.rawBody.toString('base64'), + }; + } + return { workflowData: [ - this.helpers.returnJsonArray(returnData) + [ + response, + ], ], }; } From 9acb03435abb6d9602c02764f29fb348c0dbd3d3 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 21 Dec 2019 19:03:24 -0600 Subject: [PATCH 3/3] :zap: Fix rawBody --- packages/nodes-base/nodes/Webhook.node.ts | 71 ++++++++++------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index da3ecd3cdb..427334b5a1 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -4,6 +4,7 @@ import { import { IDataObject, + INodeExecutionData, INodeTypeDescription, INodeType, IWebhookResponseData, @@ -208,16 +209,6 @@ export class Webhook implements INodeType { displayName: 'Options', name: 'options', type: 'collection', - displayOptions: { - show: { - responseData: [ - 'firstEntryJson', - ], - responseMode: [ - 'lastNode', - ], - }, - }, placeholder: 'Add Option', default: {}, options: [ @@ -225,6 +216,16 @@ export class Webhook implements INodeType { displayName: 'Response Content-Type', name: 'responseContentType', type: 'string', + displayOptions: { + show: { + '/responseData': [ + 'firstEntryJson', + ], + '/responseMode': [ + 'lastNode', + ], + }, + }, default: '', placeholder: 'application/xml', description: 'Set a custom content-type to return if another one as the "application/json" should be returned.', @@ -233,6 +234,16 @@ export class Webhook implements INodeType { displayName: 'Property Name', name: 'responsePropertyName', type: 'string', + displayOptions: { + show: { + '/responseData': [ + 'firstEntryJson', + ], + '/responseMode': [ + 'lastNode', + ], + }, + }, default: 'data', description: 'Name of the property to return the data of instead of the whole JSON.', }, @@ -245,36 +256,13 @@ export class Webhook implements INodeType { }, ], }, - { - displayName: 'Options', - name: 'options', - type: 'collection', - displayOptions: { - show: { - responseMode: [ - 'onReceived', - ], - }, - }, - placeholder: 'Add Option', - default: {}, - options: [ - { - displayName: 'Raw Body', - name: 'rawBody', - type: 'boolean', - default: false, - description: 'Raw body (binary)', - }, - ], - }, ], }; async webhook(this: IWebhookFunctions): Promise { const authentication = this.getNodeParameter('authentication', 0) as string; - const options = this.getNodeParameter('options', 0) as string; + const options = this.getNodeParameter('options', 0) as IDataObject; const req = this.getRequestObject(); const resp = this.getResponseObject(); const headers = this.getHeaderData(); @@ -316,19 +304,24 @@ export class Webhook implements INodeType { return authorizationError(resp, realm, 403); } } - const response = { + + // @ts-ignore + const mimeType = headers['content-type'] || 'application/json'; + + const response: INodeExecutionData = { json: { body: this.getBodyData(), headers, query: this.getQueryData(), }, }; - // @ts-ignore if (options.rawBody) { - // @ts-ignore response.binary = { - // @ts-ignore - data: req.rawBody.toString('base64'), + data: { + // @ts-ignore + data: req.rawBody.toString('base64'), + mimeType, + } }; }