Skip to content
Browse files

Linting

  • Loading branch information...
1 parent fc44d1d commit 7605c80f26545b76d0dc1ddbd689f9b11defdddc @novemberborn novemberborn committed Mar 21, 2012
Showing with 24 additions and 19 deletions.
  1. +2 −2 bin/http-console
  2. +22 −17 lib/http-console.js
View
4 bin/http-console
@@ -29,8 +29,8 @@ var argv = process.argv.slice(2), args = [],
verbose: false
};
-while (arg = argv.shift()) {
- if (option = arg.match(/^--?([\w-]+)$/)) {
+while ((arg = argv.shift())) {
+ if ((option = arg.match(/^--?([\w-]+)$/))) {
switch (option[1]) {
case 'cookies':
options.rememberCookies = true;
View
39 lib/http-console.js
@@ -12,7 +12,7 @@ require('./ext');
try {
var inspect = require('eyes').inspector();
} catch (e) {
- var inspect = function (obj) { util.puts(util.inspect(obj).white) }
+ inspect = function (obj) { util.puts(util.inspect(obj).white); };
}
var TEST_HTTP_METHODS = /^(GET|POST|PUT|PATCH|HEAD|DELETE)/i;
@@ -21,7 +21,7 @@ var consoles = [];
this.Console = function (host, port, options) {
this.host = host;
- this.port = parseInt(port);
+ this.port = parseInt(port, 10);
this.options = options;
this.timeout = this.options.timeout ? 5000 : 0;
this.path = [];
@@ -81,7 +81,7 @@ this.Console.prototype = new(function () {
this.headers['Host'] = this.host;
- for (var k in this.headers) { headers[k] = this.headers[k] }
+ for (var k in this.headers) { headers[k] = this.headers[k]; }
method = method.toUpperCase();
path = encodeURI(path);
@@ -107,9 +107,9 @@ this.Console.prototype = new(function () {
res.setEncoding('utf8');
- if (that.options.rememberCookies) { that.rememberCookies(res.headers) }
- res.on('data', function (chunk) { body += chunk });
- res.on('end', function () { callback(res, body) });
+ if (that.options.rememberCookies) { that.rememberCookies(res.headers); }
+ res.on('data', function (chunk) { body += chunk; });
+ res.on('end', function () { callback(res, body); });
}).on('error', function (e) {
util.error(e.toString().red);
that.prompt();
@@ -135,6 +135,7 @@ this.Console.prototype = new(function () {
that = this,
match, req;
+ var prompt = true;
if (this.pending) {
req = this.request(this.pending.method, this.pending.path, {
'Content-Length' : command.length
@@ -152,7 +153,8 @@ this.Console.prototype = new(function () {
req.write(command);
req.end();
- return this.pending = null;
+ this.pending = null;
+ prompt = false;
} else if (command[0] === '/') {
if (command === '//') {
this.path = [];
@@ -196,7 +198,7 @@ this.Console.prototype = new(function () {
}
} else if (command[0] === '\\') {
this.exec(command.replace(/^\\/, '.'));
- } else if (match = command.match(/^([a-zA-Z-]+):\s*(.*)/)) {
+ } else if ((match = command.match(/^([a-zA-Z-]+):\s*(.*)/))) {
if (match[2]) {
this.headers[match[1]] = match[2];
} else {
@@ -210,7 +212,7 @@ this.Console.prototype = new(function () {
if (command.length > 0) {
parts = command[0].split("?");
if (parts[0]) {
- path.push(parts[0])
+ path.push(parts[0]);
}
}
@@ -230,30 +232,33 @@ this.Console.prototype = new(function () {
});
}).end();
}
- return;
+ prompt = false;
} else if (command) {
util.puts(("unknown command '" + command + "'").yellow.bold);
}
- this.prompt();
+
+ if (prompt) {
+ this.prompt();
+ }
};
this.printResponse = function (res, body, callback) {
var status = ('HTTP/' + res.httpVersion +
' ' + res.statusCode +
' ' + http.STATUS_CODES[res.statusCode]).bold, output;
- if (res.statusCode >= 500) { status = status.red }
- else if (res.statusCode >= 400) { status = status.yellow }
- else if (res.statusCode >= 300) { status = status.cyan }
- else { status = status.green }
+ if (res.statusCode >= 500) { status = status.red; }
+ else if (res.statusCode >= 400) { status = status.yellow; }
+ else if (res.statusCode >= 300) { status = status.cyan; }
+ else { status = status.green; }
util.puts(status);
this.printHeaders(res.headers);
util.print('\n');
- try { output = JSON.parse(body) }
- catch (_) { output = body.trim() }
+ try { output = JSON.parse(body); }
+ catch (_) { output = body.trim(); }
if (typeof(output) === 'string') {
output.length > 0 && util.print(output.white + '\n');

0 comments on commit 7605c80

Please sign in to comment.
Something went wrong with that request. Please try again.