Skip to content

Commit

Permalink
Remove dependency to Request module #271
Browse files Browse the repository at this point in the history
  • Loading branch information
mbilbille authored and jcrugzz committed Sep 15, 2014
1 parent 08fccc8 commit a567631
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions lib/winston/transports/http.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var util = require('util'),
winston = require('../../winston'),
request = require('request'),
http = require('http'),
https = require('https'),
Stream = require('stream').Stream,
Transport = require('./transport').Transport;

Expand Down Expand Up @@ -47,20 +48,27 @@ Http.prototype._request = function (options, callback) {
delete options.auth;
delete options.path;

options = { json: options };
options.method = 'POST';
options.url = 'http'
+ (this.ssl ? 's' : '')
+ '://'
+ (auth ? auth.username + ':' : '')
+ (auth ? auth.password + '@' : '')
+ this.host
+ ':'
+ this.port
+ '/'
+ path.replace(/^\//, '');

return request(options, callback);
// Prepare options for outgoing HTTP request
req = (self.ssl ? https : http).request({
host: this.host,
port: this.port,
path: path.replace(/^\//, ''),
method: 'POST',
headers: { 'Content-Type': 'application/json' },
auth: (auth) ? auth.username + ':' + this.auth.password : ''
});

req.write(JSON.stringify(options));

req.end();

req.on('error', callback);

req.on('response', function (res) {
res.on('end', function () {
callback(null, res);
});
});
};

//
Expand Down Expand Up @@ -99,7 +107,7 @@ Http.prototype.log = function (level, msg, meta, callback) {
delete meta.auth;
}
}

this._request(options, function (err, res, body) {
if (res && res.statusCode !== 200) {
err = new Error('HTTP Status Code: ' + res.statusCode);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cycle": "1.0.x",
"eyes": "0.1.x",
"pkginfo": "0.3.x",
"request": "2.16.x",
"jsonquest": "0.2.x",
"stack-trace": "0.0.x"
},
"devDependencies": {
Expand Down

0 comments on commit a567631

Please sign in to comment.