diff --git a/lib/solr.js b/lib/solr.js index 49a72c1d..e8641198 100644 --- a/lib/solr.js +++ b/lib/solr.js @@ -42,12 +42,13 @@ exports.createClient = createClient; * of JSON native serializer/deserializer * @param solrVersion ['3.2', '4.0', '5.0', '5.1'], check lib/utils/version.js for full reference * @param {Number} [ipVersion=4] - pass it to http/https lib's "family" option + * @param {Object} request - request options * * @return {Client} * @api public */ -function createClient(host, port, core, path, agent, secure, bigint, solrVersion, ipVersion){ +function createClient(host, port, core, path, agent, secure, bigint, solrVersion, ipVersion, request){ var options = (typeof host === 'object') ? host : { host : host, port : port, @@ -57,7 +58,8 @@ function createClient(host, port, core, path, agent, secure, bigint, solrVersion secure : secure, bigint : bigint, solrVersion: solrVersion, - ipVersion: ipVersion == 6 ? 6 : 4 + ipVersion: ipVersion == 6 ? 6 : 4, + request: request }; return new Client(options); } @@ -75,6 +77,7 @@ function createClient(host, port, core, path, agent, secure, bigint, solrVersion * @param {Boolean} [options.secure=false] - if true HTTPS will be used instead of HTTP * @param {Boolean} [options.bigint=false] - if true JSONbig serializer/deserializer will be used instead * of JSON native serializer/deserializer + * @param {Object} options.request - request options * @param {Number} [ipVersion=4] - pass it to http/https lib's "family" option * * @return {Client} @@ -92,7 +95,8 @@ function Client(options){ bigint : options.bigint || false, get_max_request_entity_size: options.get_max_request_entity_size || false, solrVersion: options.solrVersion || versionUtils.Solr3_2, - ipVersion: options.ipVersion == 6 ? 6 : 4 + ipVersion: options.ipVersion == 6 ? 6 : 4, + request: options.request || null }; // Default paths of all request handlers @@ -519,7 +523,8 @@ Client.prototype.update = function(data,options,callback){ bigint : this.options.bigint, authorization : this.options.authorization, agent : this.options.agent, - ipVersion : this.options.ipVersion + ipVersion : this.options.ipVersion, + request: this.request }; return postJSON(params,callback); } @@ -655,11 +660,12 @@ Client.prototype.get = function(handler,query,callback){ bigint: this.options.bigint, authorization: this.options.authorization, agent: this.options.agent, - ipVersion: this.options.ipVersion + ipVersion: this.options.ipVersion, + request: this.options.request }; + return getJSON(params, callback); } else { - // Funnel this through a POST because it's too large return this.post(handler, query, callback); } @@ -711,7 +717,8 @@ Client.prototype.post = function(handler,query,callback){ bigint : this.options.bigint, authorization : this.options.authorization, agent : this.options.agent, - ipVersion : this.options.ipVersion + ipVersion : this.options.ipVersion, + request: this.options.request }; return postForm(params,callback); } @@ -784,6 +791,7 @@ Client.prototype.ping = function(callback){ * @param {Boolean} params.secure - * @param {Boolean} params.bigint - * @param {http.Agent} [params.agent] - + * @param {Object} params.request - request options * @param {Function} callback(err,obj) - a function executed when the Solr server responds or an error occurs * @param {Error} callback().err * @param {Object} callback().obj - JSON response sent by the Solr server deserialized @@ -810,6 +818,10 @@ function postForm(params,callback){ family : params.ipVersion }; + if (params.request) { + options = Object.assign(options, params.request); + } + if(params.agent !== undefined){ options.agent = params.agent; } @@ -840,6 +852,7 @@ function postForm(params,callback){ * @param {Boolean} params.secure - * @param {Boolean} params.bigint - * @param {http.Agent} [params.agent] - + * @param {Object} params.request - request options * @param {Function} callback(err,obj) - a function executed when the Solr server responds or an error occurs * @param {Error} callback().err * @param {Object} callback().obj - JSON response sent by the Solr server deserialized @@ -860,6 +873,10 @@ function getJSON(params,callback){ family: params.ipVersion }; + if (params.request) { + options = Object.assign(options, params.request); + } + if(params.agent !== undefined){ options.agent = params.agent; }