mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +00:00
Update http.js
This commit is contained in:
parent
fd18d9d150
commit
dbe48f9624
41
lib/http.js
41
lib/http.js
|
@ -16,7 +16,8 @@ var PROCESS_VERSION = SYS.getProcessVersion();
|
|||
var DEFAULT_USER_AGENT = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + PROCESS_VERSION + "; " + DEVICE_UUID + "; abuse@catswords.net)";
|
||||
|
||||
var HTTPObject = function(engine) {
|
||||
this.interface = null;
|
||||
var _interface = null;
|
||||
|
||||
this.contentType = "application/x-www-form-urlencoded";
|
||||
this.requestBody = "";
|
||||
this.responseBody = null;
|
||||
|
@ -78,7 +79,7 @@ var HTTPObject = function(engine) {
|
|||
|
||||
this.create = function() {
|
||||
if (this.engine == "MSXML") {
|
||||
this.interface = CreateObject([
|
||||
_interface = CreateObject([
|
||||
"Microsoft.XMLHTTP",
|
||||
"WinHttp.WinHttpRequest.5.1",
|
||||
"Msxml3.XMLHTTP",
|
||||
|
@ -96,12 +97,13 @@ var HTTPObject = function(engine) {
|
|||
"Msxml2.ServerXMLHTTP.3.0"
|
||||
]);
|
||||
} else if (this.engine == "CURL") {
|
||||
this.interface = SHELL.create();
|
||||
this.interface.setPrefix("bin\\curl"); // the location of cURL binary
|
||||
_interface = SHELL.create();
|
||||
_interface.setPrefix("bin\\curl"); // the location of cURL binary
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
this.jqEnabled = function() {
|
||||
return (typeof(window) !== "undefined" && typeof(window.jQuery) !== "undefined");
|
||||
};
|
||||
|
@ -152,11 +154,8 @@ var HTTPObject = function(engine) {
|
|||
};
|
||||
|
||||
this.setEngine = function(engine) {
|
||||
if (typeof(engine) == "string") {
|
||||
this.engine = engine.toUpperCase();
|
||||
} else {
|
||||
this.engine = engine;
|
||||
}
|
||||
this.engine = String(engine).toUpperCase();
|
||||
this.create();
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -233,7 +232,7 @@ var HTTPObject = function(engine) {
|
|||
|
||||
this.getHeader = function(key) {
|
||||
try {
|
||||
return this.interface.getResponseHeader(key);
|
||||
return _interface.getResponseHeader(key);
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.getHeader() -> ", e.message);
|
||||
}
|
||||
|
@ -241,7 +240,7 @@ var HTTPObject = function(engine) {
|
|||
|
||||
this.getHeaders = function() {
|
||||
try {
|
||||
var raw = this.interface.getAllResponseHeaders();
|
||||
var raw = _interface.getAllResponseHeaders();
|
||||
|
||||
return raw.split(/[\r\n]+/).filter(function(s) {
|
||||
return s.trim().length > 0;
|
||||
|
@ -372,11 +371,11 @@ var HTTPObject = function(engine) {
|
|||
// Open
|
||||
switch (this.method) {
|
||||
case "POST":
|
||||
this.interface.open(method, url, this.isAsynchronous);
|
||||
_interface.open(method, url, this.isAsynchronous);
|
||||
break;
|
||||
|
||||
case "GET":
|
||||
this.interface.open(method, url, this.isAsynchronous);
|
||||
_interface.open(method, url, this.isAsynchronous);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -429,23 +428,23 @@ var HTTPObject = function(engine) {
|
|||
try {
|
||||
if (this.engine == "MSXML") {
|
||||
for (var key in this.headers) {
|
||||
this.interface.setRequestHeader(key, this.evaluate(this.headers[key]));
|
||||
_interface.setRequestHeader(key, this.evaluate(this.headers[key]));
|
||||
}
|
||||
|
||||
switch (this.method) {
|
||||
case "GET":
|
||||
this.interface.send();
|
||||
_interface.send();
|
||||
break;
|
||||
|
||||
default:
|
||||
this.interface.send(this.serialize());
|
||||
_interface.send(this.serialize());
|
||||
}
|
||||
|
||||
// Waiting a response
|
||||
while (this.interface.readyState < 4) sleep(100);
|
||||
while (_interface.readyState < 4) sleep(100);
|
||||
|
||||
// Get response text
|
||||
responseText = this.interface.responseText;
|
||||
responseText = _interface.responseText;
|
||||
} else if (this.engine == "CURL") {
|
||||
if (this.states.length > 0) {
|
||||
// Make CURL context
|
||||
|
@ -567,7 +566,7 @@ var HTTPObject = function(engine) {
|
|||
cmd.push(state.url);
|
||||
|
||||
// Get response text
|
||||
responseText = this.interface.setCharset(this.charset).exec(cmd);
|
||||
responseText = _interface.setCharset(this.charset).exec(cmd);
|
||||
|
||||
// Reload a cookie in the pipe
|
||||
if (this.isLoggingCookie) {
|
||||
|
@ -587,7 +586,7 @@ var HTTPObject = function(engine) {
|
|||
}
|
||||
|
||||
// Get debuging text
|
||||
debuggingText = this.interface.stderr.read();
|
||||
debuggingText = _interface.stderr.read();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1049,7 +1048,7 @@ exports.parseURL = parseURL;
|
|||
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
|
||||
exports.defaultUserAgent = DEFAULT_USER_AGENT; // compatible with the specific case
|
||||
|
||||
exports.VERSIONINFO = "HTTP request module (http.js) version 0.7.19";
|
||||
exports.VERSIONINFO = "HTTP client module (http.js) version 0.7.20";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user