Update http.js

This commit is contained in:
Namhyeon Go 2022-05-30 20:19:46 +09:00 committed by GitHub
parent 5a2bf30b38
commit b93cac5e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ var HTTPObject = function(engine) {
"protocol": "http",
"host": "127.0.0.1",
"port": 80,
"credential": null // { username: "user", password: "pass" }
"credential": null // { username: "user", password: "pass" }
};
this.engine = (typeof(engine) !== "undefined" ? engine : "MSXML");
@ -35,14 +35,14 @@ var HTTPObject = function(engine) {
this.states = [];
this.variables = {
"uuidv4": RAND.uuidv4,
"base64json": function(v) { // e.g. {base64json VARIABLE_NAME}
"base64json": function(v) { // e.g. {base64json VARIABLE_NAME}
return BASE64.encode(JSON.stringify(v));
},
"unixnow": function(diff) { // e.g. {unixnow -300} (seconds)
"unixnow": function(diff) { // e.g. {unixnow -300} (seconds)
var t = parseInt(diff);
return Math.floor(new Date().getTime() / 1000) - t;
},
"unixnowms": function(diff) { // e.g. {unixnowms -300000} (milliseconds)
"unixnowms": function(diff) { // e.g. {unixnowms -300000} (milliseconds)
var t = parseInt(diff);
return Math.floor(new Date().getTime()) - t;
}
@ -60,7 +60,7 @@ var HTTPObject = function(engine) {
this.isLoggingCookie = false;
this.debuggingText = '';
this.curlOptions = [];
this.curlOptions = [];
this.create = function() {
if (this.engine == "MSXML") {
@ -129,7 +129,7 @@ var HTTPObject = function(engine) {
}
return this;
};
this.setProxy = function(proxy) {
for (var k in proxy) {
if (k in this.proxy) {
@ -168,7 +168,7 @@ var HTTPObject = function(engine) {
this.headers[key] = value;
return this;
};
this.setCookie = function(cookie) {
this.cookie = cookie;
};
@ -270,7 +270,7 @@ var HTTPObject = function(engine) {
}
this.setUserAgent = function(agent) {
this.userAgent = agent;
this.userAgent = agent;
return this;
};
@ -329,9 +329,9 @@ var HTTPObject = function(engine) {
this.open = function(method, url) {
var url = this.serializeParameters(url);
this.setMethod(method.toUpperCase()); // set method
this.pushState(null, null, url); // push state
this.setHeader("User-Agent", (this.userAgent != null ? this.evaluate(this.userAgent) : '')); // user agent
this.setMethod(method.toUpperCase()); // set method
this.pushState(null, null, url); // push state
this.setHeader("User-Agent", (this.userAgent != null ? this.evaluate(this.userAgent) : '')); // user agent
try {
if (this.engine == "MSXML") {
@ -370,7 +370,7 @@ var HTTPObject = function(engine) {
for (var key in this.headers) {
this.interface.setRequestHeader(key, this.evaluate(this.headers[key]));
}
switch (this.method) {
case "GET":
this.interface.send();
@ -395,7 +395,7 @@ var HTTPObject = function(engine) {
if (this.isDebugging) {
cmd.push("-v");
}
if (this.isFollowRedirect) {
cmd.push("-L");
}
@ -425,7 +425,7 @@ var HTTPObject = function(engine) {
cmd.push("-A");
cmd.push((this.userAgent != null ? this.evaluate(this.userAgent) : ''));
// --connect-timeout
if (this.connectTimeout > 0) {
cmd.push("--connect-timeout");
@ -477,7 +477,7 @@ var HTTPObject = function(engine) {
cmd.push("-o");
cmd.push(this.saveTo);
}
// if the count of this.curlOptions greater than 0
if (this.curlOptions.length > 0) {
cmd = cmd.concat(this.curlOptions);
@ -577,7 +577,7 @@ var HTTPObject = function(engine) {
console.error("HTTPObject.patch() ->", e.message);
}
};
this.pushState = function(state, title, url) {
this.states.push({
"state": state,
@ -589,17 +589,16 @@ var HTTPObject = function(engine) {
this.popState = function() {
return this.states.pop();
};
this.setVariable = function(k, v) {
this.variables[k] = v;
};
this.setVariables = function(variables) {
try {
var variables = (typeof(variables) !== "undefined") ? variables : {};
for (var k in variables)
this.setVariable(k, variables[k])
;
this.setVariable(k, variables[k]);
} catch (e) {
console.error("HTTPObject.setVariables() ->", e.message);
}
@ -610,7 +609,10 @@ var HTTPObject = function(engine) {
var str = String(str);
var Lpos = str.indexOf('{');
var Rpos = str.indexOf('}', Lpos + 1);
var s0 = '', s1 = [], s2 = null, s3, s4;
var s0 = '',
s1 = [],
s2 = null,
s3, s4;
while (Lpos > -1 && Rpos > -1) {
s0 = str.substring(Lpos + 1, Rpos);
@ -652,17 +654,17 @@ var HTTPObject = function(engine) {
this.connectTimeout = seconds;
return this;
};
this.setIsDebugging = function(flag) {
this.isDebugging = flag;
return this;
};
this.setCredential = function(cred) {
this.credential = cred;
return this;
};
this.setIsFollowRedirect = function(flag) {
this.isFollowRedirect = flag;
return this;
@ -681,7 +683,7 @@ var HTTPObject = function(engine) {
var tagName = "script";
var a = this.responseBody.indexOf('<' + tagName + ' ');
var b = a < 0 ? -1 : this.responseBody.indexOf('</' + tagName + '>', a);
while (a > -1 && b > -1) {
var outerHTML = this.responseBody.substring(a, b + tagName.length + 3);
var innerHTML = this.responseBody.substring(this.responseBody.indexOf('>', a), b);
@ -721,7 +723,7 @@ var HTTPObject = function(engine) {
if (typeof this.responseBody !== "string") {
return [];
}
var urls = [];
var response = this.responseBody;
var pos = response.indexOf('<iframe ');
@ -750,7 +752,7 @@ var HTTPObject = function(engine) {
console.warn("Existing proxy settings will be reset.");
switch(_debugger) {
switch (_debugger) {
case "FIDDLER":
this.proxy = {
"enabled": true,