Update har.js
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run

This commit is contained in:
Namhyeon Go 2024-08-03 17:49:22 +09:00 committed by GitHub
parent ac2e1117a7
commit 256ca14284
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,47 +15,48 @@ var HARObject = function() {
this.entryIndex = index; this.entryIndex = index;
}; };
this.addFilter = function(f) {
this.filters.push(f);
};
this.load = function(filename) { this.load = function(filename) {
this.filename = filename; this.filename = filename;
this.data = JSON.parse(FILE.readFile(this.filename, PipeIPC.CdoUTF_8)); this.data = JSON.parse(FILE.readFile(this.filename, PipeIPC.CdoUTF_8));
return this; return this;
}; };
this.test = function(entry, test) {
if (typeof test !== "function")
return true;
this.play = function(callback) { try {
return test(this, entry, entry.request, entry.response, this.entryIndex);
} catch (e) {
console.warn(e.message);
}
return true;
};
this.play = function(callback, test) {
var entries = this.data.log.entries; var entries = this.data.log.entries;
while (this.entryIndex < entries.length) { while (this.entryIndex < entries.length) {
var entry = entries[this.entryIndex]; var entry = entries[this.entryIndex];
var i = 0; if (this.test(entry, test)) {
while (i < this.filters.length && typeof this.filters[i] === "function") { if (typeof callback !== "function") {
try { console.log(
if (!this.filters[i](entry)) '[' + entry.startedDateTime + ']',
return; '"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"',
} catch (e) { entry.request.url,
console.error(e.message); entry.request.httpVersion,
} entry.response.status,
i++; entry.response.content.size
} );
} else {
if (typeof callback !== "function") { try {
console.log( callback(this, entry, entry.request, entry.response, this.entryIndex);
'[' + entry.startedDateTime + ']', } catch (e) {
'"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"', console.error(e.message);
entry.request.url, }
entry.request.httpVersion,
entry.response.status,
entry.response.content.size
);
} else {
try {
callback(this, entry, entry.request, entry.response, this.entryIndex);
} catch (e) {
console.error(e.message);
} }
} }
@ -74,7 +75,7 @@ var HARObject = function() {
exports.HARObject = HARObject; exports.HARObject = HARObject;
exports.VERSIONINFO = "HAR(HTTP Archive) manipulate and replay tools version 0.1.4"; exports.VERSIONINFO = "HAR(HTTP Archive) manipulate and replay tools version 0.1.5";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = require; exports.require = require;