mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 09:24:58 +00:00
Update har.js
This commit is contained in:
parent
ac2e1117a7
commit
256ca14284
63
lib/har.js
63
lib/har.js
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user