diff --git a/README.md b/README.md index 76d4b11..6449f49 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,18 @@ In the future the server certificate will be extracted from the BinarySecurityTo ### SSL Just specify an http**s** address in any of the previous samples. +### HTTP Request options [Optional] + +Add any of the available http request options like timeout, proxy etc. while sending a ws request. +List of all available options: [Request Options Callback](https://github.com/request/request#requestoptions-callback) +Pass on the options as a JSON Object to constructor argument of Http handler as shown below: + +`````javascript + +var handlers = [ new Addr("http://schemas.xmlsoap.org/ws/2004/08/addressing") + , new Http({timeout: 3000}) + ] +````` ### All together now `````javascript var ws = require('ws.js') @@ -340,4 +352,3 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/yaronn/ws.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge") - diff --git a/lib/handlers/client/http.js b/lib/handlers/client/http.js index ccd4c3d..8607dcd 100644 --- a/lib/handlers/client/http.js +++ b/lib/handlers/client/http.js @@ -3,19 +3,36 @@ var utils = require('../../utils') exports.HttpClientHandler = HttpClientHandler -function HttpClientHandler() {} +function HttpClientHandler() { + if(arguments.length == 1) { + this._options = arguments[0]; + } +} + +function jsonConcat(o1, o2) { + for (var key in o2) { + o1[key] = o2[key]; + } + return o1; +} HttpClientHandler.prototype.send = function(ctx, callback) { - request.post({ url: ctx.url - , body: ctx.request - , headers: { "SOAPAction": ctx.action - , "Content-Type": ctx.contentType - , "MIME-Version": "1.0" - } - , encoding: null - , rejectUnauthorized: false - , agentOptions: ctx.agentOptions - }, + var options = { url: ctx.url, + body: ctx.request, + headers: { "SOAPAction": ctx.action, + "Content-Type": ctx.contentType, + "MIME-Version": "1.0" + }, + encoding: null, + rejectUnauthorized: false, + agentOptions: ctx.agentOptions, + }; + + if(this._options !== 'undefined') { + options = jsonConcat(options, this._options); + } + + request.post(options, function (error, response, body) { ctx.response = body if (response) {