mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 21:51:04 +00:00
Update har.js
This commit is contained in:
parent
aeef44d3d9
commit
5ff6680cee
31
lib/har.js
31
lib/har.js
|
@ -5,7 +5,7 @@ var FILE = require("lib/file");
|
||||||
|
|
||||||
var HARObject = function() {
|
var HARObject = function() {
|
||||||
this.filename = null;
|
this.filename = null;
|
||||||
this.data = null;
|
this.data = {};
|
||||||
this.entryIndex = 0;
|
this.entryIndex = 0;
|
||||||
this.onEntry = null;
|
this.onEntry = null;
|
||||||
|
|
||||||
|
@ -19,23 +19,28 @@ var HARObject = function() {
|
||||||
|
|
||||||
this.load = function(filename) {
|
this.load = function(filename) {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
this.data = JSON.parse(FILE.readFile(filename, PipeIPC.CdoUTF_8));
|
this.data = JSON.parse(FILE.readFile(this.filename, PipeIPC.CdoUTF_8));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.play = function(onEntry) {
|
this.play = function() {
|
||||||
if (this.data = null)
|
var entries = this.data.log.entries;
|
||||||
return;
|
|
||||||
|
|
||||||
var entries = this.data.entries;
|
|
||||||
while (this.entryIndex < entries.length) {
|
while (this.entryIndex < entries.length) {
|
||||||
var entry = this.data.entries[entryIndex];
|
var entry = entries[this.entryIndex];
|
||||||
|
|
||||||
if (typeof this.onEntry !== "function") {
|
if (typeof this.onEntry !== "function") {
|
||||||
console.log(entry.request.httpVersion, entry.request.method, entry.response.status, entry.request.url);
|
console.log(
|
||||||
|
'[' + entry.startedDateTime + ']',
|
||||||
|
'"' + [entry.request.method, entry.request.url, entry.request.httpVersion].join(' ') + '"',
|
||||||
|
entry.request.url,
|
||||||
|
entry.request.httpVersion,
|
||||||
|
entry.response.status,
|
||||||
|
entry.response.content.size
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
this.onEntry(this, entry, entry.request, entry.response);
|
this.onEntry(this, entry, entry.request, entry.response, this.entryIndex);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
}
|
}
|
||||||
|
@ -43,16 +48,20 @@ var HARObject = function() {
|
||||||
|
|
||||||
this.entryIndex++;
|
this.entryIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.rewind = function() {
|
this.rewind = function() {
|
||||||
this.entryIndex = 0;
|
this.entryIndex = 0;
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.HARObject = HARObject;
|
exports.HARObject = HARObject;
|
||||||
|
|
||||||
exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1.1";
|
exports.VERSIONINFO = "HAR manipulate and replay tools version 0.1.2";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user