2022-10-21 14:44:44 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.checkBypass = exports.getProxyUrl = void 0;
|
|
|
|
function getProxyUrl(reqUrl) {
|
|
|
|
const usingSsl = reqUrl.protocol === 'https:';
|
|
|
|
if (checkBypass(reqUrl)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
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) {
|
2024-01-17 09:08:10 +00:00
|
|
|
try {
|
|
|
|
return new URL(proxyVar);
|
|
|
|
}
|
|
|
|
catch (_a) {
|
|
|
|
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
|
|
|
|
return new URL(`http://${proxyVar}`);
|
|
|
|
}
|
2022-10-21 14:44:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
function checkBypass(reqUrl) {
|
|
|
|
if (!reqUrl.hostname) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-01-17 09:08:10 +00:00
|
|
|
const reqHost = reqUrl.hostname;
|
|
|
|
if (isLoopbackAddress(reqHost)) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-21 14:44:44 +00:00
|
|
|
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
|
|
|
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
|
|
|
|
const upperReqHosts = [reqUrl.hostname.toUpperCase()];
|
|
|
|
if (typeof reqPort === 'number') {
|
|
|
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
|
|
|
}
|
|
|
|
// Compare request host against noproxy
|
|
|
|
for (const upperNoProxyItem of noProxy
|
|
|
|
.split(',')
|
|
|
|
.map(x => x.trim().toUpperCase())
|
|
|
|
.filter(x => x)) {
|
2024-01-17 09:08:10 +00:00
|
|
|
if (upperNoProxyItem === '*' ||
|
|
|
|
upperReqHosts.some(x => x === upperNoProxyItem ||
|
|
|
|
x.endsWith(`.${upperNoProxyItem}`) ||
|
|
|
|
(upperNoProxyItem.startsWith('.') &&
|
|
|
|
x.endsWith(`${upperNoProxyItem}`)))) {
|
2022-10-21 14:44:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
exports.checkBypass = checkBypass;
|
2024-01-17 09:08:10 +00:00
|
|
|
function isLoopbackAddress(host) {
|
|
|
|
const hostLower = host.toLowerCase();
|
|
|
|
return (hostLower === 'localhost' ||
|
|
|
|
hostLower.startsWith('127.') ||
|
|
|
|
hostLower.startsWith('[::1]') ||
|
|
|
|
hostLower.startsWith('[0:0:0:0:0:0:0:1]'));
|
|
|
|
}
|
2022-10-21 14:44:44 +00:00
|
|
|
//# sourceMappingURL=proxy.js.map
|