Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add -H to show 'curl -i' headers un-molested

  • Loading branch information...
commit 0f3c2638bb2c8972354852ff3597ca28bfb6393f 1 parent 8d3a722
isaacs isaacs authored
Showing with 21 additions and 2 deletions.
  1. +21 −2 lib/jsonCommand.js
23 lib/jsonCommand.js
View
@@ -15,6 +15,7 @@ JSON.Command = function(args) {
this.transformedKeys = [];
this.uglyOutput = false;
this.inspectOutput = false;
+ this.headerPassthrough = false;
this.columnOutput = false;
this.useObject = null;
@@ -47,6 +48,8 @@ JSON.Command.prototype.printhelp = function() {
sys.puts(" the order specified by fields\n");
sys.puts(" -e \"js expression\" execute arbitrary js in the context of each object.\n");
sys.puts(" -i use node's sys.inspect instead of JSON.stringify\n");
+ sys.puts(" -H print headers, if they are supplied.");
+ sys.puts(" Useful for output from curl -i.\n");
sys.puts("examples:\n");
sys.puts(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
sys.puts(" json -o results\n");
@@ -80,7 +83,7 @@ JSON.Command.prototype.printex = function(ex) {
JSON.Command.prototype.processArgs = function processArgs(args) {
// copy argv to chop it up
- var a = args.slice(0);
+ var a = args.slice(0);
while (a.length > 0) {
var arg = a.shift();
@@ -112,6 +115,9 @@ JSON.Command.prototype.processArgs = function processArgs(args) {
case "-i": // use sys.inspect
this.inspectOutput = true;
break;
+ case "-H": // header passthrough
+ this.headerPassthrough = true;
+ break;
default: // json object keys
if (arg.match("=")) {
var kk = arg.split("=");
@@ -370,8 +376,21 @@ JSON.Command.prototype.processInput = function() {
if (this.jsonC.buffer.match("}{")) {
objects = this.jsonC.buffer.split("}{").join("}\n{").split("\n");
}
+
this.jsonC.buffer = objects.pop();
- this.jsonC.processObjects(objects);
+
+ if (this.jsonC.headerPassthrough) {
+ for (var i = 0, l = objects.length; i < l; i ++) {
+ process.stdout.write(objects[i]+"\r\n");
+ if (objects[i] === "") {
+ this.jsonC.headerPassthrough = false;
+ break;
+ }
+ }
+ objects.splice(0, i);
+ }
+
+ if (objects.length) this.jsonC.processObjects(objects);
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.