Update har.js

This commit is contained in:
Namhyeon Go 2024-08-03 15:51:47 +09:00 committed by GitHub
parent c6cbe96e03
commit 2e8c530ba9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,10 +6,15 @@ var HARObject = function() {
this.filename = null; this.filename = null;
this.data = null; this.data = null;
this.entryIndex = 0; this.entryIndex = 0;
this.onEntry = null;
this.setEntryIndex = function(index) { this.setEntryIndex = function(index) {
this.entryIndex = index; this.entryIndex = index;
}; };
this.setOnEntry = function(callback) {
this.onEntry = callback;
};
this.load = function(filename) { this.load = function(filename) {
this.filename = filename; this.filename = filename;
@ -17,7 +22,7 @@ var HARObject = function() {
return this; return this;
}; };
this.walk = function(onEntry) { this.play = function(onEntry) {
if (this.data = null) if (this.data = null)
return; return;
@ -25,20 +30,28 @@ var HARObject = function() {
while (this.entryIndex < entries.length) { while (this.entryIndex < entries.length) {
var entry = this.data.entries[entryIndex]; var entry = this.data.entries[entryIndex];
try { if (typeof this.onEntry !== "function") {
onEntry(this, entry, entry.request, entry.response); console.log(entry.request.httpVersion, entry.request.method, entry.response.status, entry.request.url);
} catch (e) { } else {
console.error(e.message); try {
this.onEntry(this, entry, entry.request, entry.response);
} catch (e) {
console.error(e.message);
}
} }
this.entryIndex++; this.entryIndex++;
} }
}; };
this.rewind = function() {
this.entryIndex = 0;
};
}; };
exports.HARObject = HARObject; 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.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = require; exports.require = require;