Skip to content

Commit

Permalink
[api] Add HTTP Basic Auth support in webhook transport
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki authored and indexzero committed Oct 3, 2011
1 parent ddd8bd5 commit ec90194
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/winston/transports/webhook.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
//
Expand Down

0 comments on commit ec90194

Please sign in to comment.