From 4e4c59dcec9641387fae17562428e3c94433576a Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 8 Sep 2014 15:32:06 -0700 Subject: [PATCH] track the global config and pass it to the host objects on creation --- src/lib/host.js | 5 +++-- src/lib/transport.js | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/host.js b/src/lib/host.js index d03c05673..b4705a5c5 100644 --- a/src/lib/host.js +++ b/src/lib/host.js @@ -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)) { diff --git a/src/lib/transport.js b/src/lib/transport.js index 607fb27f9..df7a2cccd 100644 --- a/src/lib/transport.js +++ b/src/lib/transport.js @@ -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);