mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
Ready use the JSON-RPC 2.0 based stateless proxy
This commit is contained in:
parent
3fa72f86d6
commit
43b5781cbd
46
lib/http.js
46
lib/http.js
|
@ -478,14 +478,22 @@ var HTTPObject = function(engine) {
|
|||
return (this.proxy.userAgent != null ? this.proxy.userAgent : this.userAgent);
|
||||
};
|
||||
|
||||
this.serialize = function() {
|
||||
this.serialize = function(url) {
|
||||
var data = "";
|
||||
|
||||
if (this.isJSONRequest() && typeof this.requestBody === "object") {
|
||||
return JSON.stringify(this.requestBody);
|
||||
data = JSON.stringify(this.requestBody);
|
||||
} else if (typeof this.requestBody === "object") {
|
||||
return this.serializeURL(this.requestBody);
|
||||
data = this.serializeURL(this.requestBody);
|
||||
} else {
|
||||
return this.evaluate(this.requestBody);
|
||||
data = this.evaluate(this.requestBody);
|
||||
}
|
||||
|
||||
if (this.proxy.type == "stateless-jsonrpc2") {
|
||||
// todo
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
this.serializeURL = function(params) {
|
||||
|
@ -506,21 +514,21 @@ var HTTPObject = function(engine) {
|
|||
// Bind parameters
|
||||
if (Object.keys(this.parameters).length > 0) {
|
||||
// Type 2
|
||||
var parameters = {};
|
||||
var params = {};
|
||||
for (var k in this.parameters) {
|
||||
if (url.indexOf(':' + k) > -1) {
|
||||
url = url.replace(':' + k, this.evaluate(this.parameters[k]));
|
||||
} else {
|
||||
parameters[k] = this.evaluate(this.parameters[k]);
|
||||
params[k] = this.evaluate(this.parameters[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Type 1
|
||||
if (Object.keys(parameters).length > 0) {
|
||||
if (Object.keys(params).length > 0) {
|
||||
if (url.indexOf('?') > -1) {
|
||||
url += '&' + this.serializeURL(parameters);
|
||||
url += '&' + this.serializeURL(params);
|
||||
} else {
|
||||
url += '?' + this.serializeURL(parameters);
|
||||
url += '?' + this.serializeURL(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,6 +628,16 @@ var HTTPObject = function(engine) {
|
|||
var responseText = null;
|
||||
var debuggingText = null;
|
||||
|
||||
// check exists the opened states
|
||||
if (this.states.length == 0) {
|
||||
console.error("No available states");
|
||||
return;
|
||||
}
|
||||
|
||||
// get opened URL from last states
|
||||
var state = this.states[this.states.length - 1];
|
||||
var url = this.getProxiedUrl(state.url);
|
||||
|
||||
// [lib/http] cURL error with non-escaped ampersand on Command Prompt #103
|
||||
var replaceAndExcludeCaretAnd = function(inputString) {
|
||||
var result = "";
|
||||
|
@ -660,7 +678,7 @@ var HTTPObject = function(engine) {
|
|||
break;
|
||||
|
||||
default:
|
||||
this._interface.send(this.serialize());
|
||||
this._interface.send(this.serialize(url));
|
||||
}
|
||||
|
||||
// Waiting a response
|
||||
|
@ -669,11 +687,8 @@ var HTTPObject = function(engine) {
|
|||
// Get response text
|
||||
responseText = this._interface.responseText;
|
||||
} else if (this.engine == "CURL") {
|
||||
if (this.states.length > 0) {
|
||||
// Make CURL context
|
||||
var state = this.states[this.states.length - 1];
|
||||
// Build the cURL command line context
|
||||
var cmd = [];
|
||||
var url = this.getProxiedUrl(state.url);
|
||||
|
||||
if (this.isDebugging) {
|
||||
cmd.push("-v");
|
||||
|
@ -736,7 +751,7 @@ var HTTPObject = function(engine) {
|
|||
// Add the request body if this is not GET method
|
||||
if (this.getMethod() !== "GET") {
|
||||
cmd.push("-d");
|
||||
cmd.push(replaceAndExcludeCaretAnd(this.serialize()));
|
||||
cmd.push(replaceAndExcludeCaretAnd(this.serialize(url)));
|
||||
}
|
||||
|
||||
// Add proxy: <[protocol://][user:password@]proxyhost[:port]>
|
||||
|
@ -810,7 +825,6 @@ var HTTPObject = function(engine) {
|
|||
|
||||
// Get debuging text
|
||||
debuggingText = this._interface.stderr.read();
|
||||
}
|
||||
|
||||
// clear manually
|
||||
this._interface.clear();
|
||||
|
|
|
@ -11,6 +11,7 @@ function JsonRpc2(url) {
|
|||
this.setUserAgent = function(agent) {
|
||||
this.userAgent = agent;
|
||||
};
|
||||
|
||||
this.invoke = function(method, params, id) {
|
||||
var result;
|
||||
var response = HTTP.create("MSXML")
|
||||
|
|
Loading…
Reference in New Issue
Block a user