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..37c9894e5 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -267,6 +267,22 @@ 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()); + assert.equal(client.getHttpHeaders().foo, 'bar'); + + client.clearHttpHeaders(); + assert.equal(Object.keys(client.getHttpHeaders()).length, 0); + done(); + }); + }); describe('Namespace number', function() { var server = null;