From 00a90ce7ab21b505686f5aaa61f19ead8e3a5fba Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Sep 2019 14:54:52 -0400 Subject: [PATCH 1/3] Adding UserAgent --- lib/logger.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index 02047b1..a4283f1 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -18,6 +18,7 @@ const validUrl = require('valid-url'); // Configuration const configs = require('./configs'); +const pkg = require('../package.json'); // Variables var loggers = []; @@ -140,7 +141,9 @@ function Logger(key, options) { this._req = { auth: { username: key } , agent: useHttps ? new Agent.HttpsAgent(configs.AGENT_SETTING) : new Agent(configs.AGENT_SETTING) - , headers: clone(configs.DEFAULT_REQUEST_HEADER) + , headers: Object.assign({}, clone(configs.DEFAULT_REQUEST_HEADER), { + 'user-agent': options.UserAgent || `${pkg.name}/${pkg.version}` + }) , qs: { hostname: this.source.hostname , mac: options.mac || undefined From f80a053dbb65ddac5967cc6f1362c78722212b3b Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Thu, 19 Sep 2019 21:12:52 -0400 Subject: [PATCH 2/3] Moving the definition of User Agent into config --- lib/configs.js | 4 ++++ lib/logger.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/configs.js b/lib/configs.js index 6664ecd..a89c087 100644 --- a/lib/configs.js +++ b/lib/configs.js @@ -1,7 +1,11 @@ +// Internal Modules +const pkg = require('../package.json'); + module.exports = { LOG_LEVELS: ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'] , DEFAULT_REQUEST_HEADER: { 'Content-Type': 'application/json; charset=UTF-8' } , DEFAULT_REQUEST_TIMEOUT: 180000 + , DEFAULT_USER_AGENT: `${pkg.name}/${pkg.version}` , MS_IN_A_DAY: 86400000 , MAX_REQUEST_TIMEOUT: 300000 , MAX_LINE_LENGTH: 32000 diff --git a/lib/logger.js b/lib/logger.js index a4283f1..164cdad 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -18,7 +18,6 @@ const validUrl = require('valid-url'); // Configuration const configs = require('./configs'); -const pkg = require('../package.json'); // Variables var loggers = []; @@ -142,7 +141,7 @@ function Logger(key, options) { auth: { username: key } , agent: useHttps ? new Agent.HttpsAgent(configs.AGENT_SETTING) : new Agent(configs.AGENT_SETTING) , headers: Object.assign({}, clone(configs.DEFAULT_REQUEST_HEADER), { - 'user-agent': options.UserAgent || `${pkg.name}/${pkg.version}` + 'user-agent': options.UserAgent || config.DEFAULT_USER_AGENT }) , qs: { hostname: this.source.hostname From 6314aae22cd9e7189d088802d33a1116dceffb56 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Thu, 19 Sep 2019 21:17:19 -0400 Subject: [PATCH 3/3] Fix Typo --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index 164cdad..ca12dce 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -141,7 +141,7 @@ function Logger(key, options) { auth: { username: key } , agent: useHttps ? new Agent.HttpsAgent(configs.AGENT_SETTING) : new Agent(configs.AGENT_SETTING) , headers: Object.assign({}, clone(configs.DEFAULT_REQUEST_HEADER), { - 'user-agent': options.UserAgent || config.DEFAULT_USER_AGENT + 'user-agent': options.UserAgent || configs.DEFAULT_USER_AGENT }) , qs: { hostname: this.source.hostname