diff --git a/lib/har.js b/lib/har.js index d4b7b4d..4c98a41 100644 --- a/lib/har.js +++ b/lib/har.js @@ -6,10 +6,15 @@ var HARObject = function() { this.filename = null; this.data = null; this.entryIndex = 0; + this.onEntry = null; this.setEntryIndex = function(index) { this.entryIndex = index; }; + + this.setOnEntry = function(callback) { + this.onEntry = callback; + }; this.load = function(filename) { this.filename = filename; @@ -17,7 +22,7 @@ var HARObject = function() { return this; }; - this.walk = function(onEntry) { + this.play = function(onEntry) { if (this.data = null) return; @@ -25,20 +30,28 @@ var HARObject = function() { while (this.entryIndex < entries.length) { var entry = this.data.entries[entryIndex]; - try { - onEntry(this, entry, entry.request, entry.response); - } catch (e) { - console.error(e.message); + if (typeof this.onEntry !== "function") { + console.log(entry.request.httpVersion, entry.request.method, entry.response.status, entry.request.url); + } else { + try { + this.onEntry(this, entry, entry.request, entry.response); + } catch (e) { + console.error(e.message); + } } this.entryIndex++; } }; + + this.rewind = function() { + this.entryIndex = 0; + }; }; exports.HARObject = HARObject; -exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1"; +exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1.1"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = require;