From e9a5d8b27005ea44f33c2d4fde16dc3204cc79b2 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Fri, 30 Oct 2015 14:18:40 -0700 Subject: [PATCH 1/2] added the ability to add HTTP headers to the client. --- lib/client.js | 17 +++++++++++++++++ test/client-test.js | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/client.js b/lib/client.js index a92c05708..07d43f447 100644 --- a/lib/client.js +++ b/lib/client.js @@ -43,6 +43,22 @@ Client.prototype.clearSoapHeaders = function() { this.soapHeaders = null; }; +Client.prototype.addHttpHeader = function(name, value) { + if (!this.httpHeaders) { + this.httpHeaders = {}; + } + this.httpHeaders[name] = value; +}; + +Client.prototype.getHttpHeaders = function() { + return this.httpHeaders; +}; + +Client.prototype.clearHttpHeaders = function() { + this.httpHeaders = {}; +}; + + Client.prototype.addBodyAttribute = function(bodyAttribute, name, namespace, xmlns) { if (!this.bodyAttributes) { this.bodyAttributes = []; @@ -168,6 +184,7 @@ Client.prototype._invoke = function(method, args, location, callback, options, e options = options || {}; //Add extra headers + for (var header in this.httpHeaders ) { headers[header] = this.httpHeaders[header]; } for (var attr in extraHeaders) { headers[attr] = extraHeaders[attr]; } // Allow the security object to add headers diff --git a/test/client-test.js b/test/client-test.js index 7f22bed42..841d129ab 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -267,6 +267,25 @@ describe('SOAP Client', function() { done(); }); }); + + it('should add http headers', function(done) { + soap.createClient(__dirname+'/wsdl/default_namespace.wsdl', function(err, client) { + assert.ok(client); + assert.ok(!client.getHttpHeaders()); + + client.addHttpHeader('foo', 'bar'); + + assert.ok(client.getHttpHeaders()); + console.log('http headers'); + console.log(client.getHttpHeaders()); + console.log(client.getHttpHeaders().foo); + assert.equal(client.getHttpHeaders().foo, 'bar'); + + client.clearHttpHeaders(); + assert.equal(Object.keys(client.getHttpHeaders()).length, 0); + done(); + }); + }); describe('Namespace number', function() { var server = null; From 0406a15bf38ab408b0477f9d013b4a09eecf5037 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Fri, 30 Oct 2015 15:11:09 -0700 Subject: [PATCH 2/2] removed console logs --- test/client-test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/client-test.js b/test/client-test.js index 841d129ab..37c9894e5 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -276,9 +276,6 @@ describe('SOAP Client', function() { client.addHttpHeader('foo', 'bar'); assert.ok(client.getHttpHeaders()); - console.log('http headers'); - console.log(client.getHttpHeaders()); - console.log(client.getHttpHeaders().foo); assert.equal(client.getHttpHeaders().foo, 'bar'); client.clearHttpHeaders();