From 2d4ef58282976a84b2e7278698e5e90ea5498525 Mon Sep 17 00:00:00 2001 From: Shweta Jain Date: Fri, 20 Jul 2018 19:13:50 +0530 Subject: [PATCH] Handle undefined tags --- lib/loggly/client.js | 9 ++++++--- lib/loggly/common.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/loggly/client.js b/lib/loggly/client.js index 492018e..4398dd9 100644 --- a/lib/loggly/client.js +++ b/lib/loggly/client.js @@ -172,9 +172,12 @@ Loggly.prototype.log = function (msg, tags, callback) { : this.tags; // - // Optionally send `X-LOGGLY-TAG` if we have them + // Optionally send `X-LOGGLY-TAG` if we have them. + // Set the 'X-LOGGLY-TAG' only when we have actually some tag value. + // The library receives "400 Bad Request" in response when the + // value of 'X-LOGGLY-TAG' is empty string in request header. // - if (tags) { + if (tags && tags.length) { // Decide whether to add tags as http headers or add them to the URI. if (this.useTagHeader) { logOptions.headers['X-LOGGLY-TAG'] = tags.join(','); @@ -227,7 +230,7 @@ Loggly.prototype.tagFilter = function (tags) { // // Remark: length may need to use Buffer.byteLength? // - return isSolid.test(tag) && tag.length <= 64; + return tag && isSolid.test(tag) && tag.length <= 64; }); }; diff --git a/lib/loggly/common.js b/lib/loggly/common.js index ef1dbe5..ab3cc48 100644 --- a/lib/loggly/common.js +++ b/lib/loggly/common.js @@ -147,7 +147,7 @@ common.loggly = function () { } } var requestOptions = { - uri: isBulk ? uri + '/tag/' + headers['X-LOGGLY-TAG'] : uri, + uri: (isBulk && headers['X-LOGGLY-TAG']) ? uri + '/tag/' + headers['X-LOGGLY-TAG'] : uri, method: method, headers: isBulk ? {} : headers || {}, // Set headers empty for bulk proxy: proxy