mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
fix and test ok #143
This commit is contained in:
parent
3842d1bea8
commit
abe59228be
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"description": "WelsonJS test profile (test-misc.json)",
|
"description": "WelsonJS test profile (test-misc.json)",
|
||||||
"released": "2024-08-29",
|
"released": "2024-09-25",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"welsonjs": "0.2.7"
|
"welsonjs": "0.2.7"
|
||||||
},
|
},
|
||||||
|
@ -90,6 +90,11 @@
|
||||||
"id": "domparser_test",
|
"id": "domparser_test",
|
||||||
"description": "DOMParser compatibility test",
|
"description": "DOMParser compatibility test",
|
||||||
"tags": ["Standards"]
|
"tags": ["Standards"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "proxy_custom_provider",
|
||||||
|
"description": "HTTP proxy with a custom provider",
|
||||||
|
"tags": ["Network", "HTTP"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
17
lib/http.js
17
lib/http.js
|
@ -258,12 +258,13 @@ var HTTPObject = function(engine) {
|
||||||
this.proxy.provider = proxy['provider'];
|
this.proxy.provider = proxy['provider'];
|
||||||
|
|
||||||
if (proxyType == "stateless") {
|
if (proxyType == "stateless") {
|
||||||
this.proxy.url = this.evaluate(availableProxy.url);
|
this.proxy.url = availableProxy.url;
|
||||||
} else {
|
} else {
|
||||||
this.proxy.protocol = proxy['protocol'] || this.proxy.protocol;
|
this.proxy.protocol = proxy['protocol'] || this.proxy.protocol;
|
||||||
this.proxy.host = proxy['host'] || this.proxy.host;
|
this.proxy.host = proxy['host'] || this.proxy.host;
|
||||||
this.proxy.port = proxy['port'] || this.proxy.port;
|
this.proxy.port = proxy['port'] || this.proxy.port;
|
||||||
this.proxy.credential = proxy['credential'] || this.proxy.credential;
|
this.proxy.credential = proxy['credential'] || this.proxy.credential;
|
||||||
|
this.proxy.url = proxy['url'] || this.proxy.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("Please check documentation:", availableProxy.documentation);
|
console.info("Please check documentation:", availableProxy.documentation);
|
||||||
|
@ -277,6 +278,9 @@ var HTTPObject = function(engine) {
|
||||||
|
|
||||||
this.proxy[k] = proxy[k];
|
this.proxy[k] = proxy[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check proxy configuration
|
||||||
|
console.info("Proxy Configuration:", JSON.stringify(this.proxy));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -473,10 +477,10 @@ var HTTPObject = function(engine) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getProxiedURL = function(url) {
|
this.getProxiedURL = function(url) {
|
||||||
if (this.proxy != null && this.proxy.enabled && this.proxy.type == "stateless") {
|
this.setVariable("url", encodeURIComponent(url));
|
||||||
this.setVariable("url", encodeURIComponent(url));
|
url = this.evaluate(this.proxy.url);
|
||||||
url = this.evaluate(this.proxy.url);
|
|
||||||
}
|
console.log("Requested URL (Proxied):", url);
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
@ -865,6 +869,7 @@ var HTTPObject = function(engine) {
|
||||||
|
|
||||||
this.setVariable = function(k, v) {
|
this.setVariable = function(k, v) {
|
||||||
this.variables[k] = v;
|
this.variables[k] = v;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setVariables = function(variables) {
|
this.setVariables = function(variables) {
|
||||||
|
@ -1167,7 +1172,7 @@ exports.parseURL = parseURL;
|
||||||
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
|
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
|
||||||
exports.defaultUserAgent = DEFAULT_USER_AGENT; // compatible
|
exports.defaultUserAgent = DEFAULT_USER_AGENT; // compatible
|
||||||
|
|
||||||
exports.VERSIONINFO = "HTTP REST Client (http.js) version 0.7.32";
|
exports.VERSIONINFO = "HTTP REST Client (http.js) version 0.7.34";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
|
@ -977,10 +977,10 @@ var test_implements = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/33417367/example-of-how-to-use-peg-js
|
// https://stackoverflow.com/questions/33417367/example-of-how-to-use-peg-js
|
||||||
"pegjs": {
|
"pegjs": function() {
|
||||||
var syntax = FILE.readFile("app/assets/pegjs/test.pegjs", FILE.CdoCharset.CdoUTF_8);
|
var syntax = FILE.readFile("app/assets/pegjs/test.pegjs", FILE.CdoCharset.CdoUTF_8);
|
||||||
var parser = PEG.generate(syntax);
|
var parser = PEG.generate(syntax);
|
||||||
console.log(JSON.stringify(parser.parse("test123"));
|
console.log(JSON.stringify(parser.parse("test123")));
|
||||||
},
|
},
|
||||||
|
|
||||||
"domparser_test": function() {
|
"domparser_test": function() {
|
||||||
|
@ -1002,10 +1002,27 @@ var test_implements = {
|
||||||
console.log(JSON.stringify(result));
|
console.log(JSON.stringify(result));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// [lib/http] Proxy API services integration #143
|
// [lib/http] Proxy API services integration #143
|
||||||
"proxy_custom_provider": function() {
|
"proxy_custom_provider": function() {
|
||||||
// todo
|
var HTTP = require("lib/http");
|
||||||
|
|
||||||
|
var response = HTTP.create("CURL")
|
||||||
|
.setVariables({
|
||||||
|
"api_key": "YOUR_API_KEY",
|
||||||
|
"render_js": "false",
|
||||||
|
"residential": "false",
|
||||||
|
"country": "us"
|
||||||
|
})
|
||||||
|
.setProxy({
|
||||||
|
"enabled": true,
|
||||||
|
"provider": "scrapeops",
|
||||||
|
"type": "stateless"
|
||||||
|
})
|
||||||
|
.open("GET", "https://example.org")
|
||||||
|
.send();
|
||||||
|
|
||||||
|
console.log("responseBody:", response.responseBody);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user