mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 21:51:04 +00:00
Update http.js
This commit is contained in:
parent
8c6bd8985f
commit
6615efbd19
45
lib/http.js
45
lib/http.js
|
@ -34,6 +34,11 @@ var HTTPObject = function(engine) {
|
||||||
return BASE64.encode(JSON.stringify(v));
|
return BASE64.encode(JSON.stringify(v));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.connectTimeout = 0;
|
||||||
|
this.isDebugging = false;
|
||||||
|
this.credential = {
|
||||||
|
method: ""
|
||||||
|
};
|
||||||
|
|
||||||
this.create = function() {
|
this.create = function() {
|
||||||
if (this.engine == "MSXML") {
|
if (this.engine == "MSXML") {
|
||||||
|
@ -361,9 +366,16 @@ var HTTPObject = function(engine) {
|
||||||
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 = ["bin\\curl", "-X", this.method];
|
var cmd = ["bin\\curl"];
|
||||||
var url = state.url;
|
var url = state.url;
|
||||||
|
|
||||||
|
if (this.isDebugging) {
|
||||||
|
cmd.push("-v");
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.push("-X");
|
||||||
|
cmd.push(this.method);
|
||||||
|
|
||||||
if (Object.keys(this.headers).length > 0) {
|
if (Object.keys(this.headers).length > 0) {
|
||||||
for (var key in this.headers) {
|
for (var key in this.headers) {
|
||||||
var value = this.evaluate(this.headers[key]);
|
var value = this.evaluate(this.headers[key]);
|
||||||
|
@ -382,6 +394,20 @@ var HTTPObject = function(engine) {
|
||||||
cmd.push("-A");
|
cmd.push("-A");
|
||||||
cmd.push((this.userAgent != null ? this.userAgent : ''));
|
cmd.push((this.userAgent != null ? this.userAgent : ''));
|
||||||
|
|
||||||
|
// --connect-timeout
|
||||||
|
if (this.connectTimeout > 0) {
|
||||||
|
cmd.push("--connect-timeout");
|
||||||
|
cmd.push(this.connectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the credential parameters
|
||||||
|
switch (this.credential.method.toUpperCase()) {
|
||||||
|
case "BASIC":
|
||||||
|
cmd.push("-u");
|
||||||
|
cmd.push(this.credential.username + ":" + this.credential.password);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the request body if this is not GET method
|
// Add the request body if this is not GET method
|
||||||
if (this.method !== "GET") {
|
if (this.method !== "GET") {
|
||||||
cmd.push("-d");
|
cmd.push("-d");
|
||||||
|
@ -421,7 +447,7 @@ var HTTPObject = function(engine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("ResponseText: " + responseText);
|
console.log("Received", responseText.length, "bytes");
|
||||||
|
|
||||||
if (this.isJSONResponse()) {
|
if (this.isJSONResponse()) {
|
||||||
if (typeof(WScript) !== "undefined") {
|
if (typeof(WScript) !== "undefined") {
|
||||||
|
@ -573,6 +599,21 @@ var HTTPObject = function(engine) {
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setConnectTimeout = function(seconds) {
|
||||||
|
this.connectTimeout = seconds;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setIsDebugging = function(flag) {
|
||||||
|
this.isDebugging = flag;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setCredential = function(cred) {
|
||||||
|
this.credential = cred;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
this.create();
|
this.create();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user