track the global config and pass it to the host objects on creation

This commit is contained in:
Spencer Alger
2014-09-08 15:32:06 -07:00
parent eb4e0136a6
commit 4e4c59dcec
2 changed files with 7 additions and 5 deletions

View File

@ -23,8 +23,9 @@ Host.defaultPorts = {
https: 443
};
function Host(config) {
function Host(config, globalConfig) {
config = config || {};
globalConfig = globalConfig || {};
// defaults
this.protocol = 'http';
@ -34,7 +35,7 @@ function Host(config) {
this.auth = null;
this.query = null;
this.headers = null;
this.suggestCompression = false;
this.suggestCompression = !!globalConfig.suggestCompression;
if (typeof config === 'string') {
if (!startsWithProtocolRE.test(config)) {

View File

@ -12,7 +12,7 @@ var patchSniffOnConnectionFault = require('./transport/sniff_on_connection_fault
function Transport(config) {
var self = this;
config = config || {};
config = self._config = config || {};
var LogClass = (typeof config.log === 'function') ? config.log : require('./log');
config.log = this.log = new LogClass(config);
@ -60,7 +60,7 @@ function Transport(config) {
}
var hosts = _.map(hostsConfig, function (conf) {
return (conf instanceof Host) ? conf : new Host(conf);
return (conf instanceof Host) ? conf : new Host(conf, self._config);
});
if (randomizeHosts) {
@ -339,6 +339,7 @@ Transport.prototype.sniff = function (cb) {
var connectionPool = this.connectionPool;
var nodesToHostCallback = this.nodesToHostCallback;
var log = this.log;
var globalConfig = this._config;
// make cb a function if it isn't
cb = typeof cb === 'function' ? cb : _.noop;
@ -359,7 +360,7 @@ Transport.prototype.sniff = function (cb) {
}
connectionPool.setHosts(_.map(hostsConfigs, function (hostConfig) {
return new Host(hostConfig);
return new Host(hostConfig, globalConfig);
}));
}
cb(err, resp, status);