From 9acb03435abb6d9602c02764f29fb348c0dbd3d3 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 21 Dec 2019 19:03:24 -0600 Subject: [PATCH] :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, + } }; }