Skip to content
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
26 changes: 25 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ Client.prototype.configure = function (settings) {
return this;
};

/**
* Internal method to wrap the generate a wrapped callback
*
* Fixes issues with etcd nodes redirecting
*
* @param {Object} options
* @param {Function} cb
* @return {Function}
* @private
*
*/
Client.prototype._wrap = function(options, cb) {
retries = 0;
wrapped = function (err, resp, body) {
if (!body && resp.headers.location && retries < 3) {
retries ++;
options.uri = resp.headers.location;
request(resp.headers.location, options, wrapped);
return;
}
cb.apply(this, arguments);
};
return wrapped;
}

/**
* Internal method for calling the server.
Expand All @@ -74,7 +98,7 @@ Client.prototype._call = function (options, callback) {
if (this.agent) {
options.agent = this.agent
}
request(url, options, cb)
request(url, options, this._wrap(options, cb))
return this;
};

Expand Down