Update the proxy API services #143

This commit is contained in:
Namhyeon Go 2024-09-20 23:21:37 +09:00
parent de6b70a5b1
commit 9730b639b9

View File

@ -190,36 +190,34 @@ var HTTPObject = function(engine) {
};
this.setProxy = function(proxy) {
for (var k in proxy) {
var v = proxy[k];
// set the proxy provider
if ("provider" in proxy) {
var proxyType = proxy['type'] || this.proxy['type'];
var availableProxy = AVAILABLE_PROXIES.find(function(x) {
return x.provider == proxy['provider'] && x.type == proxyType;
});
switch (k) {
case "provider":
var proxyType = proxy['type'] || this.proxy['type'];
var availableProxy = AVAILABLE_PROXIES.find(function(x) {
return x.provider == v && x.type == proxyType;
});
if (typeof availableProxy !== "undefined") {
this.proxy.provider = proxy['provider'];
if (typeof availableProxy !== "undefined") {
this.proxy.provider = v;
if (proxyType == "stateless") {
this.proxy.url = this.evaluate(v);
} else {
var params = parseURL(this.evaluate(v));
this.proxy.protocol = params.protocol;
this.proxy.host = params.host;
this.proxy.port = params.port;
this.proxy.credential = params.credential;
}
}
break;
default:
this.proxy[k] = v;
break;
if (proxyType == "stateless") {
this.proxy.url = this.evaluate(availableProxy.url);
} else {
this.proxy.protocol = proxy['protocol'] || this.proxy.protocol;
this.proxy.host = proxy['host'] || this.proxy.host;
this.proxy.port = proxy['port'] || this.proxy.port;
this.proxy.credential = proxy['credential'] || this.proxy.credential;
}
}
}
// override proxy configurations
for (var k in proxy) {
if (k == "provider")
continue;
this.proxy[k] = proxy[k];
}
return this;
};
@ -1149,7 +1147,7 @@ exports.parseURL = parseURL;
exports.DEFAULT_USER_AGENT = DEFAULT_USER_AGENT;
exports.defaultUserAgent = DEFAULT_USER_AGENT; // compatible with the specific case
exports.VERSIONINFO = "HTTP client module (http.js) version 0.7.26";
exports.VERSIONINFO = "HTTP client module (http.js) version 0.7.27";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;