Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(solr): Add ability to inject options to the request #223

Merged
merged 4 commits into from
Dec 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lib/solr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down