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

NEW: Added option to createClient function to add additional headers to ... #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 28 additions & 6 deletions lib/solr.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ exports.createClient = createClient;
* @param {Boolean} [secure=false] - if true HTTPS will be used instead of HTTP
* @param {Boolean} [bigint=false] - if true JSONbig serializer/deserializer will be used instead
* of JSON native serializer/deserializer
* @param {Object} [headers={}] - object that contains a map of additional HTTP headers to add to Solr requests
*
* @return {Client}
* @api public
*/

function createClient(host, port, core, path, agent, secure, bigint){
function createClient(host, port, core, path, agent, secure, bigint, headers){
var options = (typeof host === 'object') ? host : {
host : host,
port : port,
core : core,
path : path,
agent : agent,
secure : secure,
bigint : bigint
bigint : bigint,
headers : headers
};
return new Client(options);
}
Expand Down Expand Up @@ -82,7 +84,8 @@ function Client(options){
path : options.path || '/solr',
agent : options.agent,
secure : options.secure || false,
bigint : options.bigint || false
bigint : options.bigint || false,
headers : options.headers || {}
};

// Default paths of all request handlers
Expand Down Expand Up @@ -222,6 +225,11 @@ Client.prototype.createAddStream = function(options){
'content-type' : 'application/json',
'charset' : 'utf-8'
};

for (var key in this.options.headers) {
headers[key] = this.options.headers[key];
}

if(this.options.authorization){
headers['authorization'] = this.options.authorization;
}
Expand Down Expand Up @@ -397,7 +405,6 @@ Client.prototype.deleteByQuery = function(query,options,callback){
return this.update(data,options,callback);
}


/**
* Delete all documents
*
Expand Down Expand Up @@ -489,7 +496,8 @@ Client.prototype.update = function(data,options,callback){
secure : this.options.secure,
bigint : this.options.bigint,
authorization : this.options.authorization,
agent : this.options.agent
agent : this.options.agent,
headers : this.options.headers
};
return postJSON(params,callback);
}
Expand Down Expand Up @@ -582,7 +590,8 @@ Client.prototype.get = function(handler,query,callback){
secure : this.options.secure,
bigint : this.options.bigint,
authorization : this.options.authorization,
agent : this.options.agent
agent : this.options.agent,
headers : this.options.headers
};
return getJSON(params,callback);
}
Expand Down Expand Up @@ -670,6 +679,13 @@ function postJSON(params,callback){
'content-length': Buffer.byteLength(params.json),
'accept' : 'application/json; charset=utf-8'
};


//copy all the fields
for (var key in params.headers) {
headers[key] = params.headers[key];
}

if(params.authorization){
headers['authorization'] = params.authorization;
}
Expand Down Expand Up @@ -723,6 +739,12 @@ function getJSON(params,callback){
var headers = {
'accept' : 'application/json; charset=utf-8'
};

//copy all the fields
for (var key in params.headers) {
headers[key] = params.headers[key];
}

var options = {
host : params.host,
port : params.port,
Expand Down