From 5670bd82658b15378320b2d49ce92f93e42a2c6f Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Sat, 24 Dec 2022 19:32:33 +0000 Subject: [PATCH 1/2] Support form-data arrays --- .../@node-red/nodes/core/network/21-httprequest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index 9eac4da91..ad283657d 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -435,6 +435,10 @@ in your Node-RED user directory (${RED.settings.userDir}). formData.append(opt, val); } else if (typeof val === 'object' && val.hasOwnProperty('value')) { formData.append(opt,val.value,val.options || {}); + } else if (Array.isArray(val)) { + for (var i=0; i Date: Sat, 24 Dec 2022 20:35:51 +0000 Subject: [PATCH 2/2] Add tests --- .../nodes/core/network/21-httprequest_spec.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/nodes/core/network/21-httprequest_spec.js b/test/nodes/core/network/21-httprequest_spec.js index 0348dcea1..7584c5a54 100644 --- a/test/nodes/core/network/21-httprequest_spec.js +++ b/test/nodes/core/network/21-httprequest_spec.js @@ -2322,7 +2322,7 @@ describe('HTTP Request Node', function() { var n2 = helper.getNode("n2"); n2.on('input', function(msg) { try{ - msg.payload.should.equal(`RequestError: Parse Error: Missing expected CR after header value : http://localhost:${port}/`) + msg.payload.should.startWith(`RequestError: Parse Error:`) done() } catch (err) { done(err) @@ -2334,4 +2334,38 @@ describe('HTTP Request Node', function() { }); } }); + + describe('multipart form posts', function() { + it('should send arrays as multiple entries', function (done) { + const flow = [ + { + id: 'n1', type: 'http request', wires: [['n2']], method: 'POST', ret: 'obj', url: getTestURL('/file-upload'), headers: [ + ] + }, + { id: "n2", type: "helper" } + ]; + helper.load(httpRequestNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on('input', function(msg){ + try { + msg.payload.body.should.have.property('foo') + msg.payload.body.list.should.deepEqual(['a','b','c']) + done() + } catch (e) { + done(e) + } + }); + n1.receive({ + headers: { + 'content-type': 'multipart/form-data' + }, + payload: { + foo: 'bar', + list: [ 'a', 'b', 'c' ] + } + }); + }) + }); + }) });