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