Skip to content

Commit

Permalink
Add http method to output
Browse files Browse the repository at this point in the history
  • Loading branch information
sdepold committed Dec 11, 2015
1 parent 5397216 commit 1250e01
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ function time(start) {

function defaultHandler(request, options, cb) {
var url = (typeof options === 'string' ? urlParse(options) : options).href;
var method = '[' + (options.method || 'GET').toUpperCase() + ']';
var signature = method + ' ' + url;
var start = new Date();

setImmediate(console.log, chalk.gray(' → ' + url));
setImmediate(console.log, chalk.gray(' → ' + signature));

return request(options, cb)
.on('response', function (response) {
var status = response.statusCode;
var s = status / 100 | 0;
console.log(' ' + chalk[colorCodes[s]](status) + ' ← ' + url + ' ' + chalk.gray(time(start)));
console.log(' ' + chalk[colorCodes[s]](status) + ' ← ' + signature + ' ' + chalk.gray(time(start)));
})
.on('error', function (err) {
console.log(' ' + chalk.red('xxx') + ' ← ' + url + ' ' + chalk.red(err.message));
console.log(' ' + chalk.red('xxx') + ' ← ' + signature + ' ' + chalk.red(err.message));
});
}

Expand Down

0 comments on commit 1250e01

Please sign in to comment.