From fbd8ad3849b8146dc153c14cb0392903224d756b Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 25 Aug 2017 16:50:12 +0200 Subject: [PATCH 1/2] added custom headers to the inner requests on an batch request correct host on an batch request --- o.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/o.js b/o.js index f0206f4..efe866b 100644 --- a/o.js +++ b/o.js @@ -1234,6 +1234,19 @@ body += '--batch_' + batchGuid + '\n'; body += 'Content-Type: multipart/mixed; boundary=changeset_' + changsetGuid + '\n\n'; } + + var hostname = null; + if (base.oConfig.endpoint !== null) { + //find & remove protocol (http, https etc.) and get hostname + if (base.oConfig.endpoint.indexOf("://") > -1) { + hostname = base.oConfig.endpoint.split('/')[2]; + } else { + hostname = base.oConfig.endpoint.split('/')[0]; + } + //find & remove port number + hostname = hostname.split(':')[0]; + } + //loop over the resourceList for (var i = 0; i < resourceList.length; i++) { var res = resourceList[i]; @@ -1245,7 +1258,14 @@ body += 'Content-Type: application/http\n'; body += 'Content-Transfer-Encoding: binary\n\n'; body += res.method + ' ' + buildQuery(res) + ' HTTP/1.1\n'; - body += 'Host: ' + base.oConfig.endpoint + '\n\n'; + body += 'Host: ' + hostname + '\n'; + + for (var k = 0; k < base.oConfig.headers.length; k++) { + var header = base.oConfig.headers[k]; + body += header.name + ': ' + header.value + '\n'; + } + + body += '\n'; } //do POST if the base.save() function was called //TODO: || res.method==='PUT' || res.method==='DELETE' @@ -1254,9 +1274,15 @@ body += '--changeset_' + changsetGuid + '\n'; body += 'Content-Type: application/http\n'; body += 'Content-Transfer-Encoding: binary\n'; - body += 'Content-ID:' + i + 1 + '\n\n'; //This ID can be referenced $1/Customer + body += 'Content-ID:' + i + 1 + '\n\n'; //This ID can be referenced $1/Customer body += res.method + ' ' + buildQuery(res) + ' HTTP/1.1\n'; - body += 'Host: ' + base.oConfig.endpoint + '\n'; + body += 'Host: ' + hostname + '\n'; + + for (var k = 0; k < base.oConfig.headers.length; k++) { + var header = base.oConfig.headers[k]; + body += header.name + ': ' + header.value + '\n'; + } + body += 'Content-Type: application/json\n'; //body += 'Content-Length:' + stringData.length + '\n'; body += '\n' + stringify(resource.data) + '\n\n\n'; From b7d9ba1983b6f651e65bb9ba526480ae85d029ea Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 29 Aug 2017 12:22:49 +0200 Subject: [PATCH 2/2] test timeouts elevated --- spec/o.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/o.spec.js b/spec/o.spec.js index 596930e..3316bda 100644 --- a/spec/o.spec.js +++ b/spec/o.spec.js @@ -1,5 +1,8 @@ var o = require('../o.js'); +jasmine.getEnv().defaultTimeoutInterval = 60000; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; + describe('o.js tests:', function () { it('GET People - no endpoint - no query', function (done) {