Update http.js

This commit is contained in:
Namhyeon Go 2024-07-10 19:37:39 +09:00
parent 1309e2ab8f
commit b3a4125253

View File

@ -79,14 +79,8 @@ var HTTPObject = function(engine) {
this.isCompressedResponse = false; this.isCompressedResponse = false;
this.create = function() { this.create = function() {
switch (this.engine) { if (this.engine == "MSXML") {
case "MSXML": this._interface = typeof XMLHttpRequest !== "undefined" ? new XMLHttpRequest() : CreateObject([
if (typeof XMLHttpRequest !== "undefined") {
console.log("A");
this._interface = new XMLHttpRequest();
} else {
console.log("B");
this._interface = CreateObject([
"Microsoft.XMLHTTP", "Microsoft.XMLHTTP",
"WinHttp.WinHttpRequest.5.1", "WinHttp.WinHttpRequest.5.1",
"Msxml3.XMLHTTP", "Msxml3.XMLHTTP",
@ -103,20 +97,12 @@ var HTTPObject = function(engine) {
"Msxml2.ServerXMLHTTP.4.0", "Msxml2.ServerXMLHTTP.4.0",
"Msxml2.ServerXMLHTTP.3.0" "Msxml2.ServerXMLHTTP.3.0"
]); ]);
} } else if (this.engine == "CURL") {
break;
case "CURL":
console.log("C");
this._interface = SHELL.create(); this._interface = SHELL.create();
this._interface.setPrefix("bin\\curl.exe"); // the location of cURL binary this._interface.setPrefix("bin\\curl.exe"); // the location of cURL binary
break; } else if (this.engine == "BITS") {
case "BITS":
console.log("D");
this._interface = SHELL.create(); this._interface = SHELL.create();
this._interface.setPrefix("bitsadmin.exe"); // the location of BITS binary this._interface.setPrefix("bitsadmin.exe"); // the location of BITS binary
break;
} }
return this; return this;
@ -443,11 +429,7 @@ var HTTPObject = function(engine) {
this.setHeader("Content-Type", this.contentType); this.setHeader("Content-Type", this.contentType);
} }
console.log("engine: ", this.engine);
console.log("interface: ", typeof this._interface);
try { try {
// MSXML (XHR)
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])); this._interface.setRequestHeader(key, this.evaluate(this.headers[key]));
@ -467,14 +449,11 @@ var HTTPObject = function(engine) {
// Get response text // Get response text
responseText = this._interface.responseText; responseText = this._interface.responseText;
} } else if (this.engine == "CURL") {
// cURL
else if (this.engine == "CURL") {
if (this.states.length > 0) { if (this.states.length > 0) {
// Make CURL context // Make CURL context
var state = this.states[this.states.length - 1]; var state = this.states[this.states.length - 1];
var cmd = []; var cmd = ["bin\\curl"];
var url = state.url; var url = state.url;
if (this.isDebugging) { if (this.isDebugging) {
@ -604,19 +583,16 @@ var HTTPObject = function(engine) {
console.log("Detected charset:", detectedCharset); console.log("Detected charset:", detectedCharset);
if (detectedCharset != null && this.charset != detectedCharset) { if (detectedCharset != null && this.charset != detectedCharset) {
var this._interface = SHELL.create(); var _interface = SHELL.create();
responseText = this._interface.setCharset(detectedCharset).exec(cmd); responseText = _interface.setCharset(detectedCharset).exec(cmd);
debuggingText = this._interface.stderr.read(); debuggingText = _interface.stderr.read();
} }
} }
// Get debuging text // Get debuging text
debuggingText = this._interface.stderr.read(); debuggingText = this._interface.stderr.read();
} }
} } else if (this.engine == "BITS") {
// BITS
else if (this.engine == "BITS") {
var job_name = "welsonjs_" + PipeIPC.UUIDv4.create().substring(0, 8); var job_name = "welsonjs_" + PipeIPC.UUIDv4.create().substring(0, 8);
var job_priority = "normal"; var job_priority = "normal";
var state = this.states[this.states.length - 1]; var state = this.states[this.states.length - 1];
@ -1095,7 +1071,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 client module (http.js) version 0.7.21"; exports.VERSIONINFO = "HTTP client module (http.js) version 0.7.22";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;