Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/janhommes/o.js
Browse files Browse the repository at this point in the history
  • Loading branch information
janhommes committed Aug 30, 2017
2 parents 7ae26fd + 35d5a62 commit ac2783f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
32 changes: 29 additions & 3 deletions o.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,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];
Expand All @@ -1250,7 +1263,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'
Expand All @@ -1259,9 +1279,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';
Expand Down
3 changes: 3 additions & 0 deletions spec/o.spec.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit ac2783f

Please sign in to comment.