2024-09-28 07:36:38 +00:00
|
|
|
// http.js
|
2024-09-22 16:47:46 +00:00
|
|
|
// HTTP REST Client for WelsonJS framework
|
2024-09-25 06:52:47 +00:00
|
|
|
// Namhyeon Go (Catswords Research) <abuse@catswords.net>
|
2023-12-11 07:54:21 +00:00
|
|
|
// https://github.com/gnh1201/welsonjs
|
2022-05-30 11:09:09 +00:00
|
|
|
var SYS = require("lib/system");
|
2020-12-07 08:33:12 +00:00
|
|
|
var FILE = require("lib/file");
|
2022-01-13 07:21:20 +00:00
|
|
|
var SHELL = require("lib/shell");
|
2022-01-15 10:38:45 +00:00
|
|
|
var RAND = require("lib/rand");
|
2022-01-17 15:44:54 +00:00
|
|
|
var BASE64 = require("lib/base64");
|
2023-10-30 18:13:02 +00:00
|
|
|
var PipeIPC = require("lib/pipe-ipc");
|
2022-01-13 07:21:20 +00:00
|
|
|
|
2022-05-30 09:18:32 +00:00
|
|
|
var OS_NAME = SYS.getOS();
|
|
|
|
var OS_ARCH = SYS.getArch();
|
|
|
|
var DEVICE_UUID = SYS.getUUID();
|
2023-12-11 07:54:21 +00:00
|
|
|
var PROCESS_VERSION = SYS.getProcessVersion();
|
2024-09-21 15:10:04 +00:00
|
|
|
var DEFAULT_USER_AGENT = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + PROCESS_VERSION + "; " + DEVICE_UUID + "; abuse@catswords.net)";
|
|
|
|
|
2024-09-21 15:15:01 +00:00
|
|
|
// If you have any suggestions for partnerships, please contact us at: abuse@catswords.net
|
2024-09-21 15:10:04 +00:00
|
|
|
var AVAILABLE_PROXIES = [
|
|
|
|
{
|
|
|
|
"type": "stateless",
|
|
|
|
"provider": "scrapeops",
|
|
|
|
"url": "https://proxy.scrapeops.io/v1/?api_key={api_key}&url={url}&render_js={render_js}&residential={residential}&country={country}&keep_headers={keep_headers}",
|
|
|
|
"documentation": "https://scrapeops.io?fpr=namhyeon75"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "scrapeops",
|
|
|
|
"url": "http://scrapeops:{api_key}@residential-proxy.scrapeops.io:8181",
|
|
|
|
"documentation": "https://scrapeops.io?fpr=namhyeon75"
|
|
|
|
},
|
2024-09-27 06:53:19 +00:00
|
|
|
{
|
|
|
|
"type": "serp",
|
|
|
|
"provider": "searchapi",
|
|
|
|
"url": "https://www.searchapi.io/api/v1/search?api_key={api_key}&engine={engine}&q={q}",
|
|
|
|
"documentation": "https://www.searchapi.io/?via=namhyeon"
|
|
|
|
},
|
2024-09-28 07:44:27 +00:00
|
|
|
{
|
|
|
|
"type": "serp",
|
|
|
|
"provider": "librey",
|
2024-10-08 06:24:24 +00:00
|
|
|
"url": "https://serp.catswords.net/api.php?q={q}&p=1&t=0",
|
2024-09-28 07:44:27 +00:00
|
|
|
"documentation": "https://github.com/Ahwxorg/LibreY"
|
|
|
|
},
|
2024-10-19 11:49:16 +00:00
|
|
|
{
|
|
|
|
"type": "serp",
|
|
|
|
"provider": "invidious",
|
|
|
|
"url": "https://invidious.example.org/api/v1/search?q={q}",
|
|
|
|
"documentation": "https://docs.invidious.io/"
|
|
|
|
},
|
2024-09-21 15:10:04 +00:00
|
|
|
{
|
|
|
|
"type": "stateless-jsonrpc2",
|
|
|
|
"provider": "gnh1201/caterpillar",
|
|
|
|
"url": "http://localhost:5555",
|
|
|
|
"documentation": "https://github.com/gnh1201/caterpillar"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "gnh1201/caterpillar",
|
|
|
|
"url": "http://localhost:5555",
|
|
|
|
"documentation": "https://github.com/gnh1201/caterpillar"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "cloudflare",
|
|
|
|
"url": "http://localhost:40000",
|
|
|
|
"documentation": "https://developers.cloudflare.com/warp-client/warp-modes/"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "fiddler",
|
|
|
|
"url": "http://localhost:8888",
|
|
|
|
"documentation": "https://www.telerik.com/fiddler/fiddler-classic"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "fiddler2",
|
|
|
|
"url": "http://localhost:8866",
|
|
|
|
"documentation": "https://www.telerik.com/fiddler/fiddler-everywhere"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "mitmproxy",
|
|
|
|
"url": "http://localhost:8080",
|
|
|
|
"documetation": "https://mitmproxy.org/"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "burpsuite",
|
|
|
|
"url": "http://localhost:8080",
|
|
|
|
"documetation": "https://portswigger.net/burp"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "stateful",
|
|
|
|
"provider": "zaproxy",
|
|
|
|
"url": "http://localhost:8080",
|
|
|
|
"documetation": "https://www.zaproxy.org/"
|
|
|
|
}
|
|
|
|
];
|
2024-09-20 14:10:30 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
var HTTPObject = function(engine) {
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface = null;
|
2024-07-10 02:48:28 +00:00
|
|
|
|
2020-11-25 06:10:02 +00:00
|
|
|
this.contentType = "application/x-www-form-urlencoded";
|
2020-11-10 09:13:41 +00:00
|
|
|
this.requestBody = "";
|
|
|
|
this.responseBody = null;
|
2020-11-26 08:13:13 +00:00
|
|
|
this.method = "GET";
|
2020-11-10 09:13:41 +00:00
|
|
|
this.headers = {};
|
2020-11-25 06:10:02 +00:00
|
|
|
this.parameters = {};
|
2020-11-26 08:13:13 +00:00
|
|
|
this.dataType = null;
|
2024-05-22 09:30:07 +00:00
|
|
|
this.userAgent = DEFAULT_USER_AGENT;
|
2022-06-09 03:03:23 +00:00
|
|
|
this.isAsynchronous = false;
|
2022-01-17 09:58:52 +00:00
|
|
|
this.proxy = {
|
|
|
|
"enabled": false,
|
2024-09-20 14:10:30 +00:00
|
|
|
"type": "stateful",
|
|
|
|
"provider": "",
|
2022-01-17 09:58:52 +00:00
|
|
|
"protocol": "http",
|
|
|
|
"host": "127.0.0.1",
|
|
|
|
"port": 80,
|
2024-09-20 14:10:30 +00:00
|
|
|
"credential": null, // { username: "user", password: "pass" }
|
2024-09-27 06:53:19 +00:00
|
|
|
"url": null // stateless only
|
2022-01-17 09:58:52 +00:00
|
|
|
};
|
2022-01-13 07:21:20 +00:00
|
|
|
this.engine = (typeof(engine) !== "undefined" ? engine : "MSXML");
|
|
|
|
|
|
|
|
this.cookie = null;
|
2024-07-10 03:51:16 +00:00
|
|
|
this.storedCookie = PipeIPC.connect("volatile");
|
2022-01-13 07:21:20 +00:00
|
|
|
this.states = [];
|
2022-01-17 15:44:54 +00:00
|
|
|
this.variables = {
|
|
|
|
"uuidv4": RAND.uuidv4,
|
2022-05-30 11:19:46 +00:00
|
|
|
"base64json": function(v) { // e.g. {base64json VARIABLE_NAME}
|
2022-01-17 15:44:54 +00:00
|
|
|
return BASE64.encode(JSON.stringify(v));
|
2022-04-04 06:11:07 +00:00
|
|
|
},
|
2022-05-30 11:19:46 +00:00
|
|
|
"unixnow": function(diff) { // e.g. {unixnow -300} (seconds)
|
2022-05-06 07:52:39 +00:00
|
|
|
var t = parseInt(diff);
|
|
|
|
return Math.floor(new Date().getTime() / 1000) - t;
|
2022-04-04 06:11:07 +00:00
|
|
|
},
|
2022-05-30 11:19:46 +00:00
|
|
|
"unixnowms": function(diff) { // e.g. {unixnowms -300000} (milliseconds)
|
2022-05-06 07:52:39 +00:00
|
|
|
var t = parseInt(diff);
|
2022-05-06 08:33:50 +00:00
|
|
|
return Math.floor(new Date().getTime()) - t;
|
2022-06-09 02:35:47 +00:00
|
|
|
},
|
|
|
|
"isotime": function() {
|
2022-06-09 02:35:59 +00:00
|
|
|
return new Date().toISOString();
|
2022-01-17 15:44:54 +00:00
|
|
|
}
|
|
|
|
};
|
2022-02-18 07:50:24 +00:00
|
|
|
this.connectTimeout = 0;
|
2022-09-22 05:34:28 +00:00
|
|
|
this.maxTime = 0;
|
2022-02-18 07:50:24 +00:00
|
|
|
this.isDebugging = false;
|
|
|
|
this.credential = {
|
2022-04-14 08:46:15 +00:00
|
|
|
method: "",
|
|
|
|
username: "",
|
|
|
|
password: ""
|
2022-02-18 07:50:24 +00:00
|
|
|
};
|
2022-04-14 08:46:15 +00:00
|
|
|
this.isFollowRedirect = true;
|
2022-05-02 14:56:14 +00:00
|
|
|
this.saveTo = null;
|
|
|
|
|
|
|
|
this.isLoggingCookie = false;
|
2022-05-04 06:52:15 +00:00
|
|
|
this.debuggingText = '';
|
2020-12-07 03:48:37 +00:00
|
|
|
|
2022-05-30 11:19:46 +00:00
|
|
|
this.curlOptions = [];
|
2022-05-30 11:09:09 +00:00
|
|
|
|
2023-10-30 04:56:43 +00:00
|
|
|
this.charset = FILE.CdoCharset.CdoUTF_8;
|
2024-09-27 06:53:19 +00:00
|
|
|
this.isUseDetectCharset = false;
|
2024-04-06 11:26:58 +00:00
|
|
|
this.isVerifySSL = true;
|
2024-05-22 09:34:45 +00:00
|
|
|
this.isCompressedResponse = false;
|
2024-04-06 11:26:07 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.create = function() {
|
2024-07-10 10:37:39 +00:00
|
|
|
if (this.engine == "MSXML") {
|
|
|
|
this._interface = typeof XMLHttpRequest !== "undefined" ? new XMLHttpRequest() : CreateObject([
|
|
|
|
"Microsoft.XMLHTTP",
|
|
|
|
"WinHttp.WinHttpRequest.5.1",
|
|
|
|
"Msxml3.XMLHTTP",
|
|
|
|
"Msxml2.XMLHTTP",
|
|
|
|
"Msxml2.XMLHTTP.7.0",
|
|
|
|
"Msxml2.XMLHTTP.6.0",
|
|
|
|
"Msxml2.XMLHTTP.5.O",
|
|
|
|
"Msxml2.XMLHTTP.4.O",
|
|
|
|
"Msxml2.XMLHTTP.3.O",
|
|
|
|
"Msxml2.XMLHTTP.2.6",
|
|
|
|
"Msxml2.ServerXMLHTTP",
|
|
|
|
"Msxml2.ServerXMLHTTP.6.0",
|
|
|
|
"Msxml2.ServerXMLHTTP.5.0",
|
|
|
|
"Msxml2.ServerXMLHTTP.4.0",
|
|
|
|
"Msxml2.ServerXMLHTTP.3.0"
|
|
|
|
]);
|
|
|
|
} else if (this.engine == "CURL") {
|
|
|
|
this._interface = SHELL.create();
|
2024-09-25 06:52:08 +00:00
|
|
|
|
|
|
|
// the location of cURL binary
|
2024-09-25 06:52:47 +00:00
|
|
|
var arch = SYS.getArch();
|
2024-09-25 07:12:19 +00:00
|
|
|
if (arch.toLowerCase().indexOf("arm") > -1) {
|
2024-09-25 07:11:41 +00:00
|
|
|
this.setBinPath("bin\\x64\\curl-8.10.1_1-win64a-mingw\\bin\\curl.exe");
|
|
|
|
} else if (arch.indexOf("64") > -1) {
|
2024-09-25 06:52:08 +00:00
|
|
|
this.setBinPath("bin\\x64\\curl-8.10.1_1-win64-mingw\\bin\\curl.exe");
|
|
|
|
} else {
|
|
|
|
this.setBinPath("bin\\x86\\curl-8.10.1_1-win32-mingw\\bin\\curl.exe");
|
|
|
|
}
|
2024-09-26 10:35:43 +00:00
|
|
|
|
|
|
|
// do not clear after calling the `exec`
|
|
|
|
this._interface.setIsPreventClear(true);
|
2024-07-10 10:37:39 +00:00
|
|
|
} else if (this.engine == "BITS") {
|
|
|
|
this._interface = SHELL.create();
|
2024-08-21 14:38:48 +00:00
|
|
|
this.setBinPath("bitsadmin.exe"); // the location of BITS binary
|
2024-07-21 10:55:42 +00:00
|
|
|
} else if (this.engine == "CERT") {
|
|
|
|
this._interface = SHELL.create();
|
2024-08-21 14:38:48 +00:00
|
|
|
this.setBinPath("certutil.exe"); // the location of Certutil binary
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
2024-07-10 03:05:47 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
2020-11-26 08:13:13 +00:00
|
|
|
};
|
|
|
|
|
2024-08-21 14:38:48 +00:00
|
|
|
this.setBinPath = function(binPath) {
|
2024-09-25 07:11:41 +00:00
|
|
|
console.info(this.engine, "is use", binPath);
|
2024-08-21 14:38:48 +00:00
|
|
|
this._interface.setPrefix(binPath);
|
|
|
|
};
|
|
|
|
|
2020-11-26 08:13:13 +00:00
|
|
|
this.jqEnabled = function() {
|
|
|
|
return (typeof(window) !== "undefined" && typeof(window.jQuery) !== "undefined");
|
|
|
|
};
|
|
|
|
|
2022-06-09 02:54:32 +00:00
|
|
|
this.jqAjax = function(url, callback, onError) {
|
2022-06-09 05:00:59 +00:00
|
|
|
var options = {
|
2022-06-09 02:54:32 +00:00
|
|
|
type: this.method,
|
|
|
|
headers: this.headers,
|
|
|
|
url: this.serializeParameters(url),
|
2022-06-09 05:00:59 +00:00
|
|
|
//data: this.requestBody,
|
2022-06-09 02:54:32 +00:00
|
|
|
contentType: this.contentType,
|
|
|
|
success: callback,
|
2022-06-09 03:03:23 +00:00
|
|
|
async: this.isAsynchronous,
|
2022-06-09 02:54:32 +00:00
|
|
|
error: onError // (request, status, error)
|
2022-06-09 05:00:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (["POST", "PUT", "PATCH"].indexOf(this.method) > -1) {
|
|
|
|
options['data'] = this.requestBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setResponseBody(window.jQuery.ajax(options).responseText);
|
2020-11-26 08:13:13 +00:00
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.isJSONRequest = function() {
|
|
|
|
return (this.contentType === "application/json");
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isJSONResponse = function() {
|
2020-12-07 08:33:12 +00:00
|
|
|
try {
|
|
|
|
if (this.dataType === "json") {
|
|
|
|
return true;
|
2022-01-13 07:21:20 +00:00
|
|
|
} else if (this.engine == "MSXML") {
|
2020-12-07 08:33:12 +00:00
|
|
|
var headers = this.getHeaders();
|
|
|
|
for (var key in headers) {
|
|
|
|
var _k = key.toLowerCase();
|
|
|
|
var _v = headers[key].toLowerCase();
|
|
|
|
if (_k === "content-type" && _v === "application/json") {
|
|
|
|
this.dataType = "json";
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-07 08:33:12 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("HTTPObject.isJSONResponse() -> ", e.message);
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
this.setEngine = function(engine) {
|
2024-07-10 02:48:28 +00:00
|
|
|
this.engine = String(engine).toUpperCase();
|
|
|
|
this.create();
|
2022-01-13 07:21:20 +00:00
|
|
|
return this;
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-01-17 10:02:42 +00:00
|
|
|
this.setProxy = function(proxy) {
|
2024-09-20 14:21:37 +00:00
|
|
|
// set the proxy provider
|
|
|
|
if ("provider" in proxy) {
|
|
|
|
var proxyType = proxy['type'] || this.proxy['type'];
|
|
|
|
var availableProxy = AVAILABLE_PROXIES.find(function(x) {
|
|
|
|
return x.provider == proxy['provider'] && x.type == proxyType;
|
|
|
|
});
|
2024-09-20 14:10:30 +00:00
|
|
|
|
2024-09-20 14:21:37 +00:00
|
|
|
if (typeof availableProxy !== "undefined") {
|
2024-09-27 06:53:19 +00:00
|
|
|
this.proxy.provider = availableProxy['provider'];
|
|
|
|
this.proxy.protocol = availableProxy['protocol'] || this.proxy.protocol;
|
|
|
|
this.proxy.host = availableProxy['host'] || this.proxy.host;
|
|
|
|
this.proxy.port = availableProxy['port'] || this.proxy.port;
|
|
|
|
this.proxy.credential = availableProxy['credential'] || this.proxy.credential;
|
|
|
|
this.proxy.url = availableProxy['url'] || this.proxy.url;
|
2024-09-21 05:14:43 +00:00
|
|
|
|
|
|
|
console.info("Please check documentation:", availableProxy.documentation);
|
2024-09-20 14:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-20 14:10:30 +00:00
|
|
|
|
2024-09-20 14:21:37 +00:00
|
|
|
// override proxy configurations
|
|
|
|
for (var k in proxy) {
|
|
|
|
if (k == "provider")
|
|
|
|
continue;
|
2024-09-20 14:10:30 +00:00
|
|
|
|
2024-09-20 14:21:37 +00:00
|
|
|
this.proxy[k] = proxy[k];
|
2022-01-17 10:07:08 +00:00
|
|
|
}
|
2024-09-25 09:21:55 +00:00
|
|
|
|
|
|
|
// check proxy configuration
|
|
|
|
console.info("Proxy Configuration:", JSON.stringify(this.proxy));
|
2024-09-21 05:14:43 +00:00
|
|
|
|
2022-01-17 10:02:42 +00:00
|
|
|
return this;
|
|
|
|
};
|
2022-01-13 07:21:20 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setMethod = function(method) {
|
|
|
|
this.method = method;
|
2022-01-13 07:21:20 +00:00
|
|
|
return this;
|
2020-11-10 09:13:41 +00:00
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setDataType = function(type) {
|
|
|
|
this.dataType = type;
|
|
|
|
return this;
|
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setContentType = function(type) {
|
|
|
|
this.contentType = type;
|
2024-04-06 11:46:41 +00:00
|
|
|
this.setHeader("Content-Type", this.contentType);
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2024-04-06 11:46:41 +00:00
|
|
|
this.setCookie = function(cookie) {
|
|
|
|
this.cookie = cookie;
|
|
|
|
this.setHeader("Cookie", this.cookie);
|
|
|
|
};
|
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setRequestBody = function(data) {
|
|
|
|
this.requestBody = data;
|
|
|
|
return this;
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setResponseBody = function(data) {
|
|
|
|
this.responseBody = data;
|
|
|
|
return this;
|
2020-11-05 05:09:20 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setHeader = function(key, value) {
|
2020-11-12 03:16:31 +00:00
|
|
|
this.headers[key] = value;
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.setHeaders = function(headers) {
|
2020-12-07 08:33:12 +00:00
|
|
|
try {
|
|
|
|
var headers = (typeof(headers) !== "undefined") ? headers : {};
|
|
|
|
for (var key in headers) {
|
|
|
|
var value = headers[key];
|
2022-01-13 07:21:20 +00:00
|
|
|
|
|
|
|
switch (key.toUpperCase()) {
|
|
|
|
case "CONTENT-TYPE":
|
2022-06-08 09:15:05 +00:00
|
|
|
console.warn("Will be forget the previous CONTENT-TYPE");
|
2022-01-13 07:21:20 +00:00
|
|
|
this.setContentType(value.toLowerCase());
|
|
|
|
break;
|
|
|
|
case "COOKIE":
|
2022-06-08 09:15:05 +00:00
|
|
|
console.warn("Will be forget the previous COOKIE");
|
2022-01-13 07:21:20 +00:00
|
|
|
this.setCookie(value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.setHeader(key, value);
|
2020-12-07 08:33:12 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
2020-12-07 08:33:12 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("HTTPObject.setHeaders() -> ", e.message);
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.getHeader = function(key) {
|
2020-11-25 02:46:20 +00:00
|
|
|
try {
|
2024-07-10 10:26:58 +00:00
|
|
|
return this._interface.getResponseHeader(key);
|
2020-11-25 02:46:20 +00:00
|
|
|
} catch (e) {
|
2020-11-25 06:10:02 +00:00
|
|
|
console.error("HTTPObject.getHeader() -> ", e.message);
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.getHeaders = function() {
|
2020-11-25 02:46:20 +00:00
|
|
|
try {
|
2024-07-10 10:26:58 +00:00
|
|
|
var raw = this._interface.getAllResponseHeaders();
|
2020-11-25 02:46:20 +00:00
|
|
|
|
|
|
|
return raw.split(/[\r\n]+/).filter(function(s) {
|
|
|
|
return s.trim().length > 0;
|
|
|
|
}).map(function(s) {
|
|
|
|
return s.trim().split(": ");
|
|
|
|
}).reduce(function(acc, c) {
|
|
|
|
acc[c[0].trim()] = c[1].trim();
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
} catch (e) {
|
2020-11-25 06:10:02 +00:00
|
|
|
console.error("HTTPObject.getHeaders() -> ", e.message);
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
};
|
2020-11-05 05:32:27 +00:00
|
|
|
|
2020-11-25 06:10:02 +00:00
|
|
|
this.setParameter = function(key, value) {
|
|
|
|
this.parameters[key] = value;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getParameter = function(key) {
|
|
|
|
return this.parameters[key];
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setParameters = function(params) {
|
2020-12-07 08:33:12 +00:00
|
|
|
try {
|
|
|
|
var params = (typeof(params) !== "undefined") ? params : {};
|
|
|
|
for (var key in params) {
|
|
|
|
var value = params[key];
|
|
|
|
this.setParameter(key, value);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error("HTTPObject.setParameters() -> ", e.message);
|
2020-11-25 06:10:02 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getParameters = function() {
|
|
|
|
return this.parameters;
|
|
|
|
};
|
|
|
|
|
2020-11-12 03:16:31 +00:00
|
|
|
this.setBearerAuth = function(token) {
|
|
|
|
this.setHeader("Authorization", "Bearer " + token);
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setUseCache = function(flag) {
|
|
|
|
if (flag === false) {
|
|
|
|
this.setHeaders({
|
|
|
|
//"Pragma": "no-cache",
|
|
|
|
//"Cache-Control": "no-cache",
|
|
|
|
"If-Modified-Since": "Sat, 1 Jan 2000 00:00:00 GMT"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2022-06-09 03:03:23 +00:00
|
|
|
this.setIsAsynchronous = function(flag) {
|
|
|
|
this.isAsynchronous = flag;
|
2020-11-26 08:13:13 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-11-12 06:39:50 +00:00
|
|
|
this.setUserAgent = function(agent) {
|
2022-05-30 11:19:46 +00:00
|
|
|
this.userAgent = agent;
|
2022-01-13 07:21:20 +00:00
|
|
|
return this;
|
2020-11-12 06:39:50 +00:00
|
|
|
};
|
|
|
|
|
2020-11-25 06:10:02 +00:00
|
|
|
this.serialize = function() {
|
|
|
|
if (this.isJSONRequest() && typeof(this.requestBody) === "object") {
|
|
|
|
return JSON.stringify(this.requestBody);
|
2022-05-12 16:55:39 +00:00
|
|
|
} else if (typeof(this.requestBody) === "object") {
|
|
|
|
return this.serializeURL(this.evaluate(this.requestBody));
|
2020-11-25 06:10:02 +00:00
|
|
|
} else {
|
2022-05-12 16:51:55 +00:00
|
|
|
return this.evaluate(this.requestBody);
|
2020-11-25 06:10:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-17 09:44:31 +00:00
|
|
|
this.serializeURL = function(parameters) {
|
|
|
|
var s = [];
|
|
|
|
for (var k in parameters) {
|
|
|
|
if (parameters.hasOwnProperty(k)) {
|
2022-05-12 16:51:55 +00:00
|
|
|
s.push(encodeURIComponent(k) + "=" + encodeURIComponent(this.evaluate(parameters[k])));
|
2022-01-03 04:17:00 +00:00
|
|
|
}
|
2020-11-25 06:10:02 +00:00
|
|
|
}
|
2022-01-17 09:44:31 +00:00
|
|
|
return s.join("&");
|
2020-11-25 06:10:02 +00:00
|
|
|
};
|
|
|
|
|
2022-01-03 04:17:00 +00:00
|
|
|
// Type 1: http://domain?a=1&b=2&c=3
|
|
|
|
// Type 2: http://domain/:a/:b/:c
|
2020-11-25 06:10:02 +00:00
|
|
|
this.serializeParameters = function(url) {
|
2022-01-05 02:49:46 +00:00
|
|
|
console.log(Object.keys(this.parameters).join(","));
|
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
// Bind parameters
|
2020-11-25 06:10:02 +00:00
|
|
|
if (Object.keys(this.parameters).length > 0) {
|
2022-01-03 04:17:00 +00:00
|
|
|
// Type 2
|
|
|
|
var parameters = {};
|
|
|
|
for (var k in this.parameters) {
|
|
|
|
if (url.indexOf(':' + k) > -1) {
|
2022-01-17 15:44:54 +00:00
|
|
|
url = url.replace(':' + k, this.evaluate(this.parameters[k]));
|
2022-01-13 07:59:30 +00:00
|
|
|
} else {
|
2022-01-17 15:44:54 +00:00
|
|
|
parameters[k] = this.evaluate(this.parameters[k]);
|
2022-01-03 04:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type 1
|
2022-01-05 02:49:46 +00:00
|
|
|
if (Object.keys(parameters).length > 0) {
|
|
|
|
if (url.indexOf('?') > -1) {
|
|
|
|
url += '&' + this.serializeURL(parameters);
|
|
|
|
} else {
|
|
|
|
url += '?' + this.serializeURL(parameters);
|
|
|
|
}
|
2020-11-25 06:10:02 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-05 02:49:46 +00:00
|
|
|
|
|
|
|
console.log("Requested URL: " + url);
|
|
|
|
|
|
|
|
return url;
|
2020-11-25 06:10:02 +00:00
|
|
|
};
|
|
|
|
|
2024-09-20 14:10:30 +00:00
|
|
|
this.getProxiedURL = function(url) {
|
2024-09-27 06:53:19 +00:00
|
|
|
if (!this.proxy.enabled) return url;
|
|
|
|
|
|
|
|
if (this.proxy.type == "serp") {
|
|
|
|
var serp = this.parseSerpUrl(url);
|
|
|
|
this.setVariable("engine", serp.engine);
|
|
|
|
this.setVariable("q", encodeURIComponent(serp.keyword));
|
|
|
|
}
|
|
|
|
|
2024-09-25 09:21:55 +00:00
|
|
|
this.setVariable("url", encodeURIComponent(url));
|
|
|
|
url = this.evaluate(this.proxy.url);
|
|
|
|
|
|
|
|
console.log("Requested URL (Proxied):", url);
|
2024-09-20 14:10:30 +00:00
|
|
|
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2024-09-27 06:53:19 +00:00
|
|
|
this.parseSerpUrl = function(url) {
|
|
|
|
var getEngine = function(url) {
|
2024-09-28 07:36:38 +00:00
|
|
|
var match = url.match(/(?:https?:\/\/)?(?:www\.)?(google|youtube|bing|baidu|amazon|naver|daum)\.\w+/), result;
|
2024-09-27 06:53:19 +00:00
|
|
|
if (match) {
|
|
|
|
result = match[1];
|
2024-09-28 07:36:38 +00:00
|
|
|
if (result == "naver" || result == "daum") {
|
|
|
|
result = "google";
|
|
|
|
}
|
2024-09-27 06:53:19 +00:00
|
|
|
} else {
|
|
|
|
result = "google";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
var getKeyword = function(url) {
|
2024-09-28 07:24:24 +00:00
|
|
|
var regex = /[?&](q|wd|query|search_query|k)=([^&]*)/g;
|
2024-09-27 06:53:19 +00:00
|
|
|
var match, keywords = [];
|
|
|
|
while ((match = regex.exec(url)) !== null) {
|
|
|
|
keywords.push(match[2]);
|
|
|
|
}
|
|
|
|
return keywords.join(' ');
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
"engine": getEngine(url),
|
|
|
|
"keyword": getKeyword(url)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-26 08:13:13 +00:00
|
|
|
this.open = function(method, url) {
|
2022-01-17 09:45:33 +00:00
|
|
|
var url = this.serializeParameters(url);
|
|
|
|
|
2022-05-30 11:19:46 +00:00
|
|
|
this.setMethod(method.toUpperCase()); // set method
|
|
|
|
this.pushState(null, null, url); // push state
|
2024-04-06 11:46:41 +00:00
|
|
|
this.setHeader("User-Agent", this.evaluate(this.userAgent)); // user agent
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
try {
|
|
|
|
if (this.engine == "MSXML") {
|
2024-09-27 11:53:29 +00:00
|
|
|
// Get the proxied URL
|
|
|
|
url = this.getProxiedURL(url);
|
|
|
|
|
|
|
|
// Open the URL
|
2022-01-13 07:21:20 +00:00
|
|
|
switch (this.method) {
|
|
|
|
case "POST":
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.open(method, url, this.isAsynchronous);
|
2022-01-13 07:21:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "GET":
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.open(method, url, this.isAsynchronous);
|
2022-01-13 07:21:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-01-24 10:23:39 +00:00
|
|
|
console.warn("Switching the engine to cURL. Not supported method in MSXML: " + method);
|
|
|
|
this.setEngine("CURL");
|
2024-09-27 11:53:29 +00:00
|
|
|
console.log("Use the engine:", this.engine);
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
2024-09-27 11:53:29 +00:00
|
|
|
console.log("Use the engine:", this.engine);
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-01-13 08:50:25 +00:00
|
|
|
console.error("HTTPObject.open() ->", e.message);
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
|
|
|
};
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.send = function(callback) {
|
2022-01-13 07:21:20 +00:00
|
|
|
var responseText = null;
|
2022-09-22 05:34:28 +00:00
|
|
|
var debuggingText = null;
|
2022-01-13 07:21:20 +00:00
|
|
|
|
2024-01-24 10:23:39 +00:00
|
|
|
// [lib/http] cURL error with non-escaped ampersand on Command Prompt #103
|
|
|
|
var replaceAndExcludeCaretAnd = function(inputString) {
|
2024-04-06 11:46:41 +00:00
|
|
|
var result = "";
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
while (i < inputString.length) {
|
|
|
|
// If the found position is ^&, do not modify and add it as is to the result
|
|
|
|
if (i < inputString.length - 1 && inputString.slice(i, i + 2) === "^&") {
|
|
|
|
result += inputString.slice(i, i + 2);
|
|
|
|
i += 2;
|
2024-04-06 11:26:58 +00:00
|
|
|
} else {
|
2024-04-06 11:46:41 +00:00
|
|
|
// Replace & with ^&
|
|
|
|
if (inputString.charAt(i) === "&") {
|
|
|
|
result += "^&";
|
|
|
|
} else {
|
|
|
|
result += inputString.charAt(i);
|
|
|
|
}
|
|
|
|
i++;
|
2024-04-06 11:26:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-06 11:46:41 +00:00
|
|
|
return result;
|
|
|
|
};
|
2024-01-24 10:23:39 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
if (this.contentType != null) {
|
|
|
|
this.setHeader("Content-Type", this.contentType);
|
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-25 02:46:20 +00:00
|
|
|
try {
|
2022-01-13 07:21:20 +00:00
|
|
|
if (this.engine == "MSXML") {
|
|
|
|
for (var key in this.headers) {
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.setRequestHeader(key, this.evaluate(this.headers[key]));
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
switch (this.method) {
|
|
|
|
case "GET":
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.send();
|
2022-01-13 07:21:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.send(this.serialize());
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
// Waiting a response
|
2024-07-10 10:26:58 +00:00
|
|
|
while (this._interface.readyState < 4) sleep(100);
|
2022-01-13 07:21:20 +00:00
|
|
|
|
|
|
|
// Get response text
|
2024-07-10 10:26:58 +00:00
|
|
|
responseText = this._interface.responseText;
|
2024-07-10 10:37:39 +00:00
|
|
|
} else if (this.engine == "CURL") {
|
2022-01-13 07:21:20 +00:00
|
|
|
if (this.states.length > 0) {
|
|
|
|
// Make CURL context
|
|
|
|
var state = this.states[this.states.length - 1];
|
2024-07-21 10:55:42 +00:00
|
|
|
var cmd = [];
|
2024-09-20 14:10:30 +00:00
|
|
|
var url = this.getProxiedURL(state.url);
|
2022-01-13 07:21:20 +00:00
|
|
|
|
2022-02-18 07:50:24 +00:00
|
|
|
if (this.isDebugging) {
|
|
|
|
cmd.push("-v");
|
|
|
|
}
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2024-05-22 09:34:45 +00:00
|
|
|
if (this.isCompressedResponse) {
|
|
|
|
cmd.push("--compressed");
|
|
|
|
}
|
|
|
|
|
2022-04-14 08:46:15 +00:00
|
|
|
if (this.isFollowRedirect) {
|
|
|
|
cmd.push("-L");
|
|
|
|
}
|
2022-02-18 07:50:24 +00:00
|
|
|
|
|
|
|
cmd.push("-X");
|
|
|
|
cmd.push(this.method);
|
|
|
|
|
2022-01-13 07:29:01 +00:00
|
|
|
if (Object.keys(this.headers).length > 0) {
|
2022-01-13 07:21:20 +00:00
|
|
|
for (var key in this.headers) {
|
2022-01-17 15:44:54 +00:00
|
|
|
var value = this.evaluate(this.headers[key]);
|
2022-01-13 07:21:20 +00:00
|
|
|
if (value != null) {
|
|
|
|
cmd.push("-H");
|
|
|
|
cmd.push(key + ": " + value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-17 15:44:54 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
if (this.cookie != null) {
|
|
|
|
cmd.push("-b");
|
2022-01-17 15:44:54 +00:00
|
|
|
cmd.push(this.evaluate(this.cookie));
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
2022-01-13 08:46:57 +00:00
|
|
|
|
2022-05-02 14:56:14 +00:00
|
|
|
if (this.isLoggingCookie) {
|
|
|
|
cmd.push("-c");
|
2023-09-21 06:07:22 +00:00
|
|
|
cmd.push(this.storedCookie.path);
|
2022-05-02 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 08:47:20 +00:00
|
|
|
cmd.push("-A");
|
2024-04-06 11:46:41 +00:00
|
|
|
cmd.push(this.evaluate(this.userAgent));
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-02-18 07:50:24 +00:00
|
|
|
// --connect-timeout
|
|
|
|
if (this.connectTimeout > 0) {
|
|
|
|
cmd.push("--connect-timeout");
|
|
|
|
cmd.push(this.connectTimeout);
|
|
|
|
}
|
2022-09-22 05:34:28 +00:00
|
|
|
|
|
|
|
// --max-time
|
|
|
|
if (this.maxTime > 0) {
|
|
|
|
cmd.push("--max-time");
|
|
|
|
cmd.push(this.maxTime);
|
|
|
|
}
|
2022-02-18 07:50:24 +00:00
|
|
|
|
2022-04-04 06:11:07 +00:00
|
|
|
// Add the credential parameters
|
2022-02-18 07:50:24 +00:00
|
|
|
switch (this.credential.method.toUpperCase()) {
|
|
|
|
case "BASIC":
|
|
|
|
cmd.push("-u");
|
|
|
|
cmd.push(this.credential.username + ":" + this.credential.password);
|
|
|
|
break;
|
|
|
|
}
|
2022-01-13 07:21:20 +00:00
|
|
|
|
2022-01-17 09:44:31 +00:00
|
|
|
// Add the request body if this is not GET method
|
|
|
|
if (this.method !== "GET") {
|
2022-01-13 07:59:30 +00:00
|
|
|
cmd.push("-d");
|
2024-01-24 10:23:39 +00:00
|
|
|
cmd.push(replaceAndExcludeCaretAnd(this.serialize()));
|
2022-01-13 07:59:30 +00:00
|
|
|
}
|
2022-01-17 15:44:54 +00:00
|
|
|
|
2022-01-17 09:58:52 +00:00
|
|
|
// Add proxy: <[protocol://][user:password@]proxyhost[:port]>
|
2024-09-27 06:53:19 +00:00
|
|
|
if (this.proxy != null && this.proxy.enabled && this.proxy.type == "stateful") {
|
2022-01-17 09:58:52 +00:00
|
|
|
cmd.push("-x");
|
|
|
|
if (this.proxy.credential != null) {
|
|
|
|
cmd.push([
|
|
|
|
this.proxy.protocol,
|
|
|
|
"://",
|
|
|
|
this.proxy.credential.username,
|
|
|
|
":",
|
|
|
|
this.proxy.credential.password,
|
|
|
|
"@",
|
|
|
|
this.proxy.host,
|
|
|
|
":",
|
|
|
|
this.proxy.port
|
|
|
|
].join(""));
|
|
|
|
} else {
|
|
|
|
cmd.push([
|
|
|
|
this.proxy.protocol,
|
|
|
|
"://",
|
|
|
|
this.proxy.host,
|
|
|
|
":",
|
|
|
|
this.proxy.port
|
|
|
|
].join(""));
|
|
|
|
}
|
|
|
|
}
|
2022-01-17 09:44:31 +00:00
|
|
|
|
2022-04-20 05:02:11 +00:00
|
|
|
// if it is download
|
2022-05-02 14:56:14 +00:00
|
|
|
if (this.saveTo != null) {
|
|
|
|
cmd.push("-o");
|
|
|
|
cmd.push(this.saveTo);
|
|
|
|
}
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2024-04-06 11:26:07 +00:00
|
|
|
// If not verify SSL
|
|
|
|
if (!this.isVerifySSL) {
|
|
|
|
if (this.proxy.enabled) {
|
|
|
|
cmd.push("--proxy-insecure");
|
|
|
|
}
|
|
|
|
cmd.push("-k");
|
|
|
|
cmd.push("--ssl-no-revoke");
|
|
|
|
}
|
|
|
|
|
2022-05-30 11:09:09 +00:00
|
|
|
// if the count of this.curlOptions greater than 0
|
|
|
|
if (this.curlOptions.length > 0) {
|
|
|
|
cmd = cmd.concat(this.curlOptions);
|
|
|
|
}
|
2022-04-20 05:02:11 +00:00
|
|
|
|
|
|
|
// set the URL
|
2024-09-20 14:10:30 +00:00
|
|
|
cmd.push(url);
|
2022-01-13 07:21:20 +00:00
|
|
|
|
|
|
|
// Get response text
|
2024-07-10 10:26:58 +00:00
|
|
|
responseText = this._interface.setCharset(this.charset).exec(cmd);
|
2022-09-22 05:34:28 +00:00
|
|
|
|
2023-09-21 06:07:22 +00:00
|
|
|
// Reload a cookie in the pipe
|
|
|
|
if (this.isLoggingCookie) {
|
|
|
|
this.storedCookie.reload();
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:34:28 +00:00
|
|
|
// If enabled the charset(text encoding) detector
|
2024-09-27 06:53:19 +00:00
|
|
|
if (this.isUseDetectCharset) {
|
2022-09-22 05:34:28 +00:00
|
|
|
var detectedCharset = this.detectCharset(responseText);
|
|
|
|
console.log("Detected charset:", detectedCharset);
|
|
|
|
|
|
|
|
if (detectedCharset != null && this.charset != detectedCharset) {
|
2024-07-10 10:37:39 +00:00
|
|
|
var _interface = SHELL.create();
|
|
|
|
responseText = _interface.setCharset(detectedCharset).exec(cmd);
|
|
|
|
debuggingText = _interface.stderr.read();
|
2022-09-22 05:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-04 06:52:15 +00:00
|
|
|
|
|
|
|
// Get debuging text
|
2024-07-10 10:26:58 +00:00
|
|
|
debuggingText = this._interface.stderr.read();
|
2022-01-13 07:21:20 +00:00
|
|
|
}
|
2024-09-25 05:12:19 +00:00
|
|
|
|
2024-09-26 10:35:43 +00:00
|
|
|
// clear manually
|
2024-09-25 05:12:19 +00:00
|
|
|
this._interface.clear();
|
2024-07-10 10:37:39 +00:00
|
|
|
} else if (this.engine == "BITS") {
|
2024-07-10 03:51:16 +00:00
|
|
|
var job_name = "welsonjs_" + PipeIPC.UUIDv4.create().substring(0, 8);
|
|
|
|
var job_priority = "normal";
|
|
|
|
var state = this.states[this.states.length - 1];
|
|
|
|
var cmd = ["/transfer", job_name];
|
2024-09-20 14:10:30 +00:00
|
|
|
var url = this.getProxiedURL(state.url);
|
2024-07-10 03:51:16 +00:00
|
|
|
var out = PipeIPC.connect("volatile");
|
|
|
|
|
2024-07-10 04:03:59 +00:00
|
|
|
if (this.method == "GET") {
|
2024-07-10 11:05:45 +00:00
|
|
|
cmd = cmd.concat(["/download", "/priority", job_priority, url, SYS.getCurrentScriptDirectory() + "\\" + out.path]); // build a BITS command
|
2024-07-10 10:26:58 +00:00
|
|
|
this._interface.exec(cmd); // launch the download job
|
2024-07-10 03:56:18 +00:00
|
|
|
out.reload(); // read the downloaded data
|
|
|
|
responseText = out.read() // set the downloaded data to response text
|
2024-07-10 03:51:16 +00:00
|
|
|
|
2024-07-10 10:26:58 +00:00
|
|
|
var err = this._interface.exec(["/geterror", job_name]); // get error information
|
2024-07-10 03:56:18 +00:00
|
|
|
debuggingText = err.stdout.read(); // set the error information to debugging text
|
|
|
|
|
|
|
|
out.destroy(); // destroy the downloaded data
|
2024-07-10 03:51:16 +00:00
|
|
|
}
|
2024-07-21 10:55:42 +00:00
|
|
|
} else if (this.engine == "CERT") {
|
|
|
|
var state = this.states[this.states.length - 1];
|
|
|
|
var out = PipeIPC.connect("volatile");
|
2024-09-20 14:10:30 +00:00
|
|
|
var url = this.getProxiedURL(state.url);
|
|
|
|
var cmd = ["-urlcache", "-split", "-f", url, out.path];
|
2024-07-21 10:55:42 +00:00
|
|
|
this._interface.exec(cmd);
|
|
|
|
out.reload();
|
|
|
|
responseText = out.read();
|
|
|
|
out.destroy();
|
2024-07-10 03:51:16 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 06:11:07 +00:00
|
|
|
if (typeof responseText === "string") {
|
|
|
|
console.log("Received", responseText.length, "bytes");
|
|
|
|
} else {
|
|
|
|
console.log("No received anything");
|
|
|
|
}
|
2022-01-05 02:49:46 +00:00
|
|
|
|
2022-09-22 05:34:28 +00:00
|
|
|
if (this.isDebugging && typeof debuggingText === "string") {
|
|
|
|
this.debuggingText = debuggingText;
|
|
|
|
console.log("Created debugging text", debuggingText.length, "bytes");
|
2022-05-30 12:29:38 +00:00
|
|
|
} else {
|
|
|
|
console.log("No debugging text");
|
|
|
|
}
|
|
|
|
|
2020-11-25 02:46:20 +00:00
|
|
|
if (this.isJSONResponse()) {
|
2024-07-04 01:56:48 +00:00
|
|
|
try {
|
|
|
|
this.setResponseBody(JSON.parse(responseText));
|
|
|
|
} catch (e) {
|
|
|
|
console.error("JSON parse error: " + e.message);
|
|
|
|
this.setResponseBody({});
|
2020-12-07 08:33:12 +00:00
|
|
|
}
|
2020-11-25 02:46:20 +00:00
|
|
|
} else {
|
2022-01-13 07:21:20 +00:00
|
|
|
this.setResponseBody(responseText);
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
|
2020-11-25 02:46:20 +00:00
|
|
|
if (typeof(callback) === "function") {
|
2020-12-07 08:33:12 +00:00
|
|
|
try {
|
|
|
|
callback(this.responseBody);
|
|
|
|
} catch (e) {
|
2022-02-18 07:50:24 +00:00
|
|
|
console.log("callback of HTTPObject.send() ->", e.message);
|
2020-12-07 08:33:12 +00:00
|
|
|
}
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-02-18 07:50:24 +00:00
|
|
|
console.error("HTTPObject.send() ->", e.message);
|
2020-11-10 09:13:41 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2022-06-09 02:57:02 +00:00
|
|
|
this.get = function(url, callback, onError) {
|
2020-11-26 08:13:13 +00:00
|
|
|
try {
|
2022-06-09 02:54:32 +00:00
|
|
|
if (this.jqEnabled()) {
|
2022-06-09 02:57:02 +00:00
|
|
|
this.setMethod("GET");
|
2022-06-09 02:54:32 +00:00
|
|
|
this.jqAjax(url, callback, onError);
|
2022-06-09 03:14:24 +00:00
|
|
|
return this;
|
2022-06-09 02:54:32 +00:00
|
|
|
} else {
|
2022-06-09 02:57:02 +00:00
|
|
|
return this.open("GET", url).send(callback);
|
2022-06-09 02:54:32 +00:00
|
|
|
}
|
2020-11-26 08:13:13 +00:00
|
|
|
} catch (e) {
|
2022-06-09 02:54:32 +00:00
|
|
|
if (typeof onError === "function") onError(this, null, e);
|
2020-11-26 08:13:13 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
};
|
|
|
|
|
2022-06-09 02:57:02 +00:00
|
|
|
this.post = function(url, callback, onError) {
|
2020-11-26 08:13:13 +00:00
|
|
|
try {
|
2022-01-03 04:17:00 +00:00
|
|
|
if (this.jqEnabled()) {
|
2022-06-09 02:57:02 +00:00
|
|
|
this.setMethod("POST");
|
2022-06-09 02:54:32 +00:00
|
|
|
this.jqAjax(url, callback, onError);
|
2022-06-09 03:14:24 +00:00
|
|
|
return this;
|
2022-01-03 04:17:00 +00:00
|
|
|
} else {
|
2022-06-09 02:57:02 +00:00
|
|
|
return this.open("POST", url).send(callback);
|
2022-01-03 04:17:00 +00:00
|
|
|
}
|
2020-11-26 08:13:13 +00:00
|
|
|
} catch (e) {
|
2022-06-09 02:54:32 +00:00
|
|
|
if (typeof onError === "function") onError(this, null, e);
|
2020-11-26 08:13:13 +00:00
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
};
|
|
|
|
|
2022-06-09 02:54:32 +00:00
|
|
|
this.patch = function(url, callback, onError) {
|
2020-11-25 02:46:20 +00:00
|
|
|
try {
|
2020-11-26 08:13:13 +00:00
|
|
|
if (this.jqEnabled()) {
|
2022-06-09 02:54:32 +00:00
|
|
|
this.setMethod("PATCH");
|
|
|
|
this.jqAjax(url, callback, onError);
|
2022-06-09 03:14:24 +00:00
|
|
|
return this;
|
2020-11-12 04:36:16 +00:00
|
|
|
} else {
|
2022-06-09 02:54:32 +00:00
|
|
|
return this.open("PATCH", url).send(callback);
|
2020-11-12 04:36:16 +00:00
|
|
|
}
|
2020-11-25 02:46:20 +00:00
|
|
|
} catch (e) {
|
2022-06-09 02:54:32 +00:00
|
|
|
if (typeof onError === "function") onError(this, null, e);
|
2022-06-09 02:57:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.put = function(url, callback, onError) {
|
|
|
|
try {
|
|
|
|
if (this.jqEnabled()) {
|
|
|
|
this.setMethod("PUT");
|
|
|
|
this.jqAjax(url, callback, onError);
|
2022-06-09 03:14:24 +00:00
|
|
|
return this;
|
2022-06-09 02:57:02 +00:00
|
|
|
} else {
|
|
|
|
return this.open("PUT", url).send(callback);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (typeof onError === "function") onError(this, null, e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-09 05:06:54 +00:00
|
|
|
this._delete = function(url, callback, onError) {
|
2022-06-09 02:57:02 +00:00
|
|
|
try {
|
|
|
|
if (this.jqEnabled()) {
|
|
|
|
this.setMethod("DELETE");
|
|
|
|
this.jqAjax(url, callback, onError);
|
2022-06-09 03:14:24 +00:00
|
|
|
return this;
|
2022-06-09 02:57:02 +00:00
|
|
|
} else {
|
|
|
|
return this.open("DELETE", url).send(callback);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (typeof onError === "function") onError(this, null, e);
|
2020-11-25 02:46:20 +00:00
|
|
|
}
|
2020-11-12 04:36:16 +00:00
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-01-13 07:21:20 +00:00
|
|
|
this.pushState = function(state, title, url) {
|
|
|
|
this.states.push({
|
|
|
|
"state": state,
|
|
|
|
"title": title,
|
|
|
|
"url": url
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.popState = function() {
|
|
|
|
return this.states.pop();
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-01-17 15:44:54 +00:00
|
|
|
this.setVariable = function(k, v) {
|
|
|
|
this.variables[k] = v;
|
2024-09-25 09:21:55 +00:00
|
|
|
return this;
|
2022-01-17 15:44:54 +00:00
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-01-17 15:44:54 +00:00
|
|
|
this.setVariables = function(variables) {
|
|
|
|
try {
|
|
|
|
var variables = (typeof(variables) !== "undefined") ? variables : {};
|
2022-01-17 15:46:47 +00:00
|
|
|
for (var k in variables)
|
2022-05-30 11:19:46 +00:00
|
|
|
this.setVariable(k, variables[k]);
|
2022-01-17 15:44:54 +00:00
|
|
|
} catch (e) {
|
2022-02-18 07:50:24 +00:00
|
|
|
console.error("HTTPObject.setVariables() ->", e.message);
|
2022-01-17 15:44:54 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.evaluate = function(str) {
|
2024-04-06 11:46:41 +00:00
|
|
|
if (typeof str === "undefined" || str == null) return '';
|
|
|
|
|
2022-01-17 15:46:47 +00:00
|
|
|
var str = String(str);
|
2024-07-20 08:19:50 +00:00
|
|
|
var L = '{', R = '}';
|
|
|
|
var Lpos = str.indexOf(L);
|
|
|
|
var Rpos = str.indexOf(R, Lpos + 1);
|
2022-05-30 11:19:46 +00:00
|
|
|
var s0 = '',
|
|
|
|
s1 = [],
|
|
|
|
s2 = null,
|
|
|
|
s3, s4;
|
2022-01-17 15:44:54 +00:00
|
|
|
|
2024-08-08 02:07:52 +00:00
|
|
|
// fix #122
|
|
|
|
if (str.indexOf(L) == 0) {
|
|
|
|
try {
|
|
|
|
JSON.parse(str);
|
|
|
|
return str;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:44:54 +00:00
|
|
|
while (Lpos > -1 && Rpos > -1) {
|
2022-01-17 16:43:47 +00:00
|
|
|
s0 = str.substring(Lpos + 1, Rpos);
|
2022-05-03 04:18:39 +00:00
|
|
|
s2 = '';
|
|
|
|
s1 = s0.split(' ');
|
|
|
|
while (s1.length > 0) {
|
|
|
|
s3 = s1.pop();
|
|
|
|
|
|
|
|
if (s3 in this.variables) {
|
|
|
|
switch (typeof(this.variables[s3])) {
|
|
|
|
case "function":
|
|
|
|
s2 = this.variables[s3](s2);
|
|
|
|
break;
|
2022-01-17 15:44:54 +00:00
|
|
|
|
2022-05-03 04:18:39 +00:00
|
|
|
case "object":
|
|
|
|
s4 = this.variables[s3];
|
2022-05-06 07:52:39 +00:00
|
|
|
for (var k in s4) {
|
|
|
|
s4[k] = this.evaluate(s4[k]);
|
|
|
|
}
|
2022-05-03 04:18:39 +00:00
|
|
|
s2 = s4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
s2 = this.variables[s3];
|
2022-01-17 15:44:54 +00:00
|
|
|
}
|
2022-05-06 07:52:39 +00:00
|
|
|
} else {
|
2024-08-08 02:07:52 +00:00
|
|
|
s2 = s3;
|
2022-01-17 15:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-17 15:46:47 +00:00
|
|
|
str = str.substring(0, Lpos) + s2 + str.substring(Rpos + 1);
|
2024-07-20 08:19:50 +00:00
|
|
|
Lpos = str.indexOf(L);
|
|
|
|
Rpos = str.indexOf(R, Lpos + 1);
|
2022-01-17 15:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
};
|
2020-11-12 04:36:16 +00:00
|
|
|
|
2022-02-18 07:50:24 +00:00
|
|
|
this.setConnectTimeout = function(seconds) {
|
|
|
|
this.connectTimeout = seconds;
|
|
|
|
return this;
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-09-22 05:34:28 +00:00
|
|
|
this.setMaxTime = function(seconds) {
|
|
|
|
this.maxTime = seconds;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2022-02-18 07:50:24 +00:00
|
|
|
this.setIsDebugging = function(flag) {
|
|
|
|
this.isDebugging = flag;
|
|
|
|
return this;
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-02-18 07:50:24 +00:00
|
|
|
this.setCredential = function(cred) {
|
|
|
|
this.credential = cred;
|
|
|
|
return this;
|
|
|
|
};
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-05-03 04:13:52 +00:00
|
|
|
this.setIsFollowRedirect = function(flag) {
|
|
|
|
this.isFollowRedirect = flag;
|
2022-05-04 06:57:23 +00:00
|
|
|
return this;
|
2022-05-03 04:13:52 +00:00
|
|
|
};
|
2022-02-18 07:50:24 +00:00
|
|
|
|
2022-04-20 05:02:11 +00:00
|
|
|
this.setSaveTo = function(filename) {
|
|
|
|
this.saveTo = filename;
|
|
|
|
};
|
|
|
|
|
2022-04-25 08:49:10 +00:00
|
|
|
this.parseScripts = function() {
|
|
|
|
var scripts = [];
|
|
|
|
|
|
|
|
if (typeof this.responseBody !== "string")
|
|
|
|
return scripts;
|
|
|
|
|
|
|
|
var tagName = "script";
|
|
|
|
var a = this.responseBody.indexOf('<' + tagName + ' ');
|
|
|
|
var b = a < 0 ? -1 : this.responseBody.indexOf('</' + tagName + '>', a);
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-04-25 08:49:10 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
scripts.push({
|
|
|
|
'outerHTML': outerHTML,
|
|
|
|
'innerHTML': innerHTML
|
|
|
|
});
|
|
|
|
|
|
|
|
a = this.responseBody.indexOf('<' + tagName + ' ', b + tagName.length + 3);
|
|
|
|
b = a < 0 ? -1 : this.responseBody.indexOf('</' + tagName + '>', a);
|
|
|
|
}
|
|
|
|
|
|
|
|
return scripts;
|
|
|
|
};
|
|
|
|
|
2022-05-02 14:56:14 +00:00
|
|
|
this.setIsLoggingCookie = function(flag) {
|
|
|
|
this.isLoggingCookie = flag;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getAllCookies = function() {
|
|
|
|
var data = {};
|
|
|
|
|
2023-09-21 06:07:22 +00:00
|
|
|
var rows = splitLn(this.storedCookie.read());
|
2022-05-02 14:56:14 +00:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var cols = rows[i].split("\t");
|
|
|
|
if (cols.length == 7) {
|
|
|
|
data[cols[5]] = cols[6];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2022-05-17 09:29:39 +00:00
|
|
|
this.getFrameURLs = function() {
|
|
|
|
if (typeof this.responseBody !== "string") {
|
|
|
|
return [];
|
2022-05-30 09:18:32 +00:00
|
|
|
}
|
2022-05-30 11:19:46 +00:00
|
|
|
|
2022-05-17 09:29:39 +00:00
|
|
|
var urls = [];
|
2022-05-30 09:18:32 +00:00
|
|
|
var response = this.responseBody;
|
|
|
|
var pos = response.indexOf('<iframe ');
|
2022-05-17 09:29:39 +00:00
|
|
|
|
|
|
|
while (pos > -1) {
|
2022-05-30 09:18:32 +00:00
|
|
|
var end = response.indexOf('</iframe>', pos);
|
2022-05-17 09:29:39 +00:00
|
|
|
|
2022-09-22 05:34:28 +00:00
|
|
|
if (end < 0) {
|
|
|
|
pos = response.indexOf('<iframe ', pos + 8);
|
2022-05-17 09:29:39 +00:00
|
|
|
continue;
|
2022-05-30 09:18:32 +00:00
|
|
|
}
|
2022-05-17 09:29:39 +00:00
|
|
|
|
|
|
|
var a = response.indexOf('src="', pos);
|
|
|
|
var b = response.indexOf('"', a + 5);
|
|
|
|
if (a > 0 && b > 0) {
|
|
|
|
urls.push(response.substring(a + 5, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = response.indexOf('<iframe ', pos + end);
|
|
|
|
}
|
|
|
|
|
|
|
|
return urls;
|
|
|
|
};
|
|
|
|
|
2022-05-30 09:18:32 +00:00
|
|
|
this.attachDebugger = function(_debugger) {
|
2024-09-21 15:10:04 +00:00
|
|
|
this.setProxy({
|
2024-09-22 11:59:51 +00:00
|
|
|
"enabled": true,
|
2024-09-21 15:10:04 +00:00
|
|
|
"provider": _debugger.toLowerCase()
|
|
|
|
});
|
|
|
|
this.isVerifySSL = false;
|
|
|
|
|
|
|
|
console.warn("The existing proxy settings have been reset.");
|
2022-05-30 09:18:32 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2022-09-22 05:34:28 +00:00
|
|
|
this.setCharset = function(charset) {
|
|
|
|
this.charset = charset;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2024-09-27 06:53:19 +00:00
|
|
|
this.setIsUseDetectCharset = function(flag) {
|
|
|
|
this.isUseDetectCharset = flag;
|
2022-09-22 05:34:28 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.detectCharset = function(content) {
|
|
|
|
var charset = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var s = "charset=";
|
|
|
|
var pos = content.toLowerCase().indexOf(s);
|
|
|
|
if (pos > -1) {
|
|
|
|
var end = [
|
|
|
|
content.indexOf('"', pos + s.length),
|
|
|
|
content.indexOf('\'', pos + s.length),
|
|
|
|
content.indexOf(';', pos + s.length)
|
|
|
|
].reduce(function(a, x) {
|
|
|
|
if (a < 0 || x > 0 && x < a) a = x;
|
|
|
|
return a;
|
|
|
|
}, -1);
|
|
|
|
|
|
|
|
if (end > -1) {
|
|
|
|
var detectedCharset = content.substring(pos + s.length, end);
|
|
|
|
if (detectedCharset.length > 0 && detectedCharset.length < 16) {
|
|
|
|
charset = detectedCharset.toLowerCase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
charset = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return charset;
|
|
|
|
};
|
|
|
|
|
2023-03-09 02:38:56 +00:00
|
|
|
this.detectSSL = function() {
|
|
|
|
return (this.debuggingText.indexOf("certificate") > -1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.detectSSLCompleted = function() {
|
2023-03-09 02:42:55 +00:00
|
|
|
return this.detectSSL() && (this.debuggingText.indexOf("certificate problem") < 0);
|
2023-03-09 02:38:56 +00:00
|
|
|
};
|
|
|
|
|
2024-05-22 09:34:45 +00:00
|
|
|
this.setIsCompressedResponse = function(isCompressedResponse) {
|
|
|
|
this.isCompressedResponse = isCompressedResponse;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2020-11-10 09:13:41 +00:00
|
|
|
this.create();
|
2020-06-28 14:22:57 +00:00
|
|
|
};
|
|
|
|
|
2022-06-09 05:06:54 +00:00
|
|
|
function create(engine) {
|
|
|
|
return new HTTPObject(engine);
|
|
|
|
}
|
2020-11-10 09:13:41 +00:00
|
|
|
|
2022-06-09 05:06:54 +00:00
|
|
|
function get(url, params, headers) {
|
|
|
|
return create().setHeaders(headers).setParameters(params).setUseCache(false).get(url).responseBody;
|
|
|
|
}
|
2020-11-12 05:02:25 +00:00
|
|
|
|
2022-06-09 05:06:54 +00:00
|
|
|
function post(url, data, headers, params) {
|
|
|
|
return create().setHeaders(headers).setRequestBody(data).setParameters(params).post(url).responseBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
function patch(url, data, headers) {
|
|
|
|
return create().setHeaders(headers).setParameters(data).patch(url).responseBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
function put(url, data, headers) {
|
|
|
|
return create().setHeaders(headers).setParameters(data).put(url).responseBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _delete(url, params, headers) {
|
|
|
|
return create().setHeaders(headers).setParameters(params).setUseCache(false)._delete(url).responseBody;
|
|
|
|
}
|
|
|
|
|
2024-09-20 14:10:30 +00:00
|
|
|
function parseURL(url) {
|
2024-04-06 11:26:07 +00:00
|
|
|
var pattern = /^(?:(https?):\/\/)?(?:([^:@]+)(?::([^:@]*))?@)?([^:]+)(?::(\d{1,5}))?$/;
|
2024-09-20 14:10:30 +00:00
|
|
|
var matches = url.match(pattern);
|
2024-04-06 11:26:07 +00:00
|
|
|
if (!matches) return null;
|
|
|
|
|
|
|
|
var protocol = matches[1] || 'http';
|
|
|
|
var username = matches[2] || '';
|
|
|
|
var password = matches[3] || '';
|
2024-09-20 14:10:30 +00:00
|
|
|
var host = matches[4] || 'localhost';
|
2024-04-06 11:26:07 +00:00
|
|
|
var port = matches[5] || '';
|
|
|
|
var credential = null;
|
|
|
|
|
|
|
|
if (username != '' && password != '') {
|
|
|
|
credential = {
|
|
|
|
"username": username,
|
|
|
|
"password": password
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
"protocol": protocol,
|
|
|
|
"host": host,
|
|
|
|
"port": parseInt(port),
|
|
|
|
"credential": credential
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-28 21:04:53 +00:00
|
|
|
exports.create = create;
|
2022-06-09 05:06:54 +00:00
|
|
|
exports.get = get;
|
|
|
|
exports.post = post;
|
|
|
|
exports.patch = patch;
|
|
|
|
exports.put = put;
|
|
|
|
exports._delete = _delete;
|
2024-05-22 09:30:07 +00:00
|
|
|
|
2024-04-06 11:26:07 +00:00
|
|
|
exports.parseURL = parseURL;
|
2024-05-22 09:30:07 +00:00
|
|
|
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
|
2024-09-22 16:47:46 +00:00
|
|
|
exports.defaultUserAgent = DEFAULT_USER_AGENT; // compatible
|
2020-11-12 05:02:25 +00:00
|
|
|
|
2024-10-19 11:49:16 +00:00
|
|
|
exports.VERSIONINFO = "HTTP REST Client (http.js) version 0.7.40";
|
2022-11-25 14:11:37 +00:00
|
|
|
exports.AUTHOR = "abuse@catswords.net";
|
2020-11-10 09:13:41 +00:00
|
|
|
exports.global = global;
|
2022-05-30 11:14:24 +00:00
|
|
|
exports.require = global.require;
|