Update har.js
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

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

View File

@ -3,6 +3,7 @@
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
var PipeIPC = require("lib/pipe-ipc"); var PipeIPC = require("lib/pipe-ipc");
var FILE = require("lib/file"); var FILE = require("lib/file");
var HTTP = require("lib/http");
var HARObject = function() { var HARObject = function() {
this.filename = null; this.filename = null;
@ -10,11 +11,16 @@ var HARObject = function() {
this.entryIndex = 0; this.entryIndex = 0;
this.onEntry = null; this.onEntry = null;
this.filters = []; this.filters = [];
this.isSimulated = true;
this.setEntryIndex = function(index) { this.setEntryIndex = function(index) {
this.entryIndex = index; this.entryIndex = index;
}; };
this.setIsSimulated = function(isSimulated) {
this.isSimulated = isSimulated;
};
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));
@ -34,15 +40,37 @@ var HARObject = function() {
return true; return true;
}; };
this.send = function(entry, done) {
if (typeof entry === "undefined" || entry == null)
return;
this.play = function(callback, test) { var callback = null;
if (!this.isSimulated) {
callback = function() {
console.log("callback");
};
}
try {
done(this, entry, entry.request, entry.response, callback);
} catch (e) {
console.error(e.message);
}
};
this.play = function(done, edit, test) {
var entries = this.data.log.entries; var entries = this.data.log.entries;
if (!this.isSimulated) {
console.warn("Take care! This is not a simulated mode.");
}
while (this.entryIndex < entries.length) { while (this.entryIndex < entries.length) {
var entry = entries[this.entryIndex]; var entry = entries[this.entryIndex];
if (this.test(entry, test)) { if (this.test(entry, test)) {
if (typeof callback !== "function") { if (typeof edit !== "function") {
console.log( console.log(
'[' + entry.startedDateTime + ']', '[' + entry.startedDateTime + ']',
'"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"', '"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"',
@ -53,13 +81,15 @@ var HARObject = function() {
); );
} else { } else {
try { try {
callback(this, entry, entry.request, entry.response, this.entryIndex); entry = edit(this, entry, entry.request, entry.response, this.entryIndex);
} catch (e) { } catch (e) {
console.error(e.message); console.error(e.message);
} }
} }
} }
this.send(entry, done);
this.entryIndex++; this.entryIndex++;
} }
@ -67,7 +97,7 @@ var HARObject = function() {
}; };
this.rewind = function() { this.rewind = function() {
this.entryIndex = 0; this.setEntryIndex(0);
return this; return this;
}; };
@ -75,7 +105,7 @@ var HARObject = function() {
exports.HARObject = HARObject; exports.HARObject = HARObject;
exports.VERSIONINFO = "HAR(HTTP Archive) manipulate and replay tools version 0.1.5"; exports.VERSIONINFO = "HAR(HTTP Archive) manipulate and replay tools version 0.1.8";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = require; exports.require = require;