diff --git a/lib/winston/transports/webhook.js b/lib/winston/transports/webhook.js index 8d5a0bf32..21bb43a85 100644 --- a/lib/winston/transports/webhook.js +++ b/lib/winston/transports/webhook.js @@ -30,9 +30,9 @@ var Webhook = exports.Webhook = function (options) { this.path = options.path || '/winston-log'; if (options.auth) { - // - // TODO: add http basic auth options for outgoing HTTP requests - // + this.auth = {}; + this.auth.username = options.auth.username || ''; + this.auth.password = options.auth.password || ''; } if (options.ssl) { @@ -89,6 +89,13 @@ Webhook.prototype.log = function (level, msg, meta, callback) { options.cert = this.ssl.cert; } + if (this.auth) { + // Encode `Authorization` header used by Basic Auth + options.headers['Authorization'] = 'Basic ' + new Buffer( + this.auth.username + ':' + this.auth.password, 'utf8' + ).toString('base64'); + } + // Perform HTTP logging request req = (self.ssl ? https : http).request(options, function (res) { //