2021-11-26 20:57:51 +08:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2022-06-26 21:02:18 +08:00
|
|
|
exports.checkBypass = exports.getProxyUrl = void 0;
|
2021-11-26 20:57:51 +08:00
|
|
|
function getProxyUrl(reqUrl) {
|
2022-06-26 21:02:18 +08:00
|
|
|
const usingSsl = reqUrl.protocol === 'https:';
|
2021-11-26 20:57:51 +08:00
|
|
|
if (checkBypass(reqUrl)) {
|
2022-06-26 21:02:18 +08:00
|
|
|
return undefined;
|
2021-11-26 20:57:51 +08:00
|
|
|
}
|
2022-06-26 21:02:18 +08:00
|
|
|
const proxyVar = (() => {
|
|
|
|
if (usingSsl) {
|
|
|
|
return process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
if (proxyVar) {
|
|
|
|
return new URL(proxyVar);
|
2021-11-26 20:57:51 +08:00
|
|
|
}
|
|
|
|
else {
|
2022-06-26 21:02:18 +08:00
|
|
|
return undefined;
|
2021-11-26 20:57:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
function checkBypass(reqUrl) {
|
|
|
|
if (!reqUrl.hostname) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-26 21:02:18 +08:00
|
|
|
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
2021-11-26 20:57:51 +08:00
|
|
|
if (!noProxy) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Determine the request port
|
|
|
|
let reqPort;
|
|
|
|
if (reqUrl.port) {
|
|
|
|
reqPort = Number(reqUrl.port);
|
|
|
|
}
|
|
|
|
else if (reqUrl.protocol === 'http:') {
|
|
|
|
reqPort = 80;
|
|
|
|
}
|
|
|
|
else if (reqUrl.protocol === 'https:') {
|
|
|
|
reqPort = 443;
|
|
|
|
}
|
|
|
|
// Format the request hostname and hostname with port
|
2022-06-26 21:02:18 +08:00
|
|
|
const upperReqHosts = [reqUrl.hostname.toUpperCase()];
|
2021-11-26 20:57:51 +08:00
|
|
|
if (typeof reqPort === 'number') {
|
|
|
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
|
|
|
}
|
|
|
|
// Compare request host against noproxy
|
2022-06-26 21:02:18 +08:00
|
|
|
for (const upperNoProxyItem of noProxy
|
2021-11-26 20:57:51 +08:00
|
|
|
.split(',')
|
|
|
|
.map(x => x.trim().toUpperCase())
|
|
|
|
.filter(x => x)) {
|
|
|
|
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
exports.checkBypass = checkBypass;
|
2022-06-26 21:02:18 +08:00
|
|
|
//# sourceMappingURL=proxy.js.map
|