mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update har.js
This commit is contained in:
parent
256ca14284
commit
dbae10a4e5
40
lib/har.js
40
lib/har.js
|
@ -3,6 +3,7 @@
|
|||
// https://github.com/gnh1201/welsonjs
|
||||
var PipeIPC = require("lib/pipe-ipc");
|
||||
var FILE = require("lib/file");
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
var HARObject = function() {
|
||||
this.filename = null;
|
||||
|
@ -10,11 +11,16 @@ var HARObject = function() {
|
|||
this.entryIndex = 0;
|
||||
this.onEntry = null;
|
||||
this.filters = [];
|
||||
this.isSimulated = true;
|
||||
|
||||
this.setEntryIndex = function(index) {
|
||||
this.entryIndex = index;
|
||||
};
|
||||
|
||||
this.setIsSimulated = function(isSimulated) {
|
||||
this.isSimulated = isSimulated;
|
||||
};
|
||||
|
||||
this.load = function(filename) {
|
||||
this.filename = filename;
|
||||
this.data = JSON.parse(FILE.readFile(this.filename, PipeIPC.CdoUTF_8));
|
||||
|
@ -35,14 +41,36 @@ var HARObject = function() {
|
|||
return true;
|
||||
};
|
||||
|
||||
this.play = function(callback, test) {
|
||||
this.send = function(entry, done) {
|
||||
if (typeof entry === "undefined" || entry == null)
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
if (!this.isSimulated) {
|
||||
console.warn("Take care! This is not a simulated mode.");
|
||||
}
|
||||
|
||||
while (this.entryIndex < entries.length) {
|
||||
var entry = entries[this.entryIndex];
|
||||
|
||||
if (this.test(entry, test)) {
|
||||
if (typeof callback !== "function") {
|
||||
if (typeof edit !== "function") {
|
||||
console.log(
|
||||
'[' + entry.startedDateTime + ']',
|
||||
'"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"',
|
||||
|
@ -53,13 +81,15 @@ var HARObject = function() {
|
|||
);
|
||||
} else {
|
||||
try {
|
||||
callback(this, entry, entry.request, entry.response, this.entryIndex);
|
||||
entry = edit(this, entry, entry.request, entry.response, this.entryIndex);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.send(entry, done);
|
||||
|
||||
this.entryIndex++;
|
||||
}
|
||||
|
||||
|
@ -67,7 +97,7 @@ var HARObject = function() {
|
|||
};
|
||||
|
||||
this.rewind = function() {
|
||||
this.entryIndex = 0;
|
||||
this.setEntryIndex(0);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -75,7 +105,7 @@ var HARObject = function() {
|
|||
|
||||
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.global = global;
|
||||
exports.require = require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user