github.com/nektos/act@v0.2.63/pkg/runner/testdata/actions/node12/node_modules/@actions/http-client/lib/proxy.js (about) 1 "use strict"; 2 Object.defineProperty(exports, "__esModule", { value: true }); 3 exports.checkBypass = exports.getProxyUrl = void 0; 4 function getProxyUrl(reqUrl) { 5 const usingSsl = reqUrl.protocol === 'https:'; 6 if (checkBypass(reqUrl)) { 7 return undefined; 8 } 9 const proxyVar = (() => { 10 if (usingSsl) { 11 return process.env['https_proxy'] || process.env['HTTPS_PROXY']; 12 } 13 else { 14 return process.env['http_proxy'] || process.env['HTTP_PROXY']; 15 } 16 })(); 17 if (proxyVar) { 18 try { 19 return new URL(proxyVar); 20 } 21 catch (_a) { 22 if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://')) 23 return new URL(`http://${proxyVar}`); 24 } 25 } 26 else { 27 return undefined; 28 } 29 } 30 exports.getProxyUrl = getProxyUrl; 31 function checkBypass(reqUrl) { 32 if (!reqUrl.hostname) { 33 return false; 34 } 35 const reqHost = reqUrl.hostname; 36 if (isLoopbackAddress(reqHost)) { 37 return true; 38 } 39 const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''; 40 if (!noProxy) { 41 return false; 42 } 43 // Determine the request port 44 let reqPort; 45 if (reqUrl.port) { 46 reqPort = Number(reqUrl.port); 47 } 48 else if (reqUrl.protocol === 'http:') { 49 reqPort = 80; 50 } 51 else if (reqUrl.protocol === 'https:') { 52 reqPort = 443; 53 } 54 // Format the request hostname and hostname with port 55 const upperReqHosts = [reqUrl.hostname.toUpperCase()]; 56 if (typeof reqPort === 'number') { 57 upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`); 58 } 59 // Compare request host against noproxy 60 for (const upperNoProxyItem of noProxy 61 .split(',') 62 .map(x => x.trim().toUpperCase()) 63 .filter(x => x)) { 64 if (upperNoProxyItem === '*' || 65 upperReqHosts.some(x => x === upperNoProxyItem || 66 x.endsWith(`.${upperNoProxyItem}`) || 67 (upperNoProxyItem.startsWith('.') && 68 x.endsWith(`${upperNoProxyItem}`)))) { 69 return true; 70 } 71 } 72 return false; 73 } 74 exports.checkBypass = checkBypass; 75 function isLoopbackAddress(host) { 76 const hostLower = host.toLowerCase(); 77 return (hostLower === 'localhost' || 78 hostLower.startsWith('127.') || 79 hostLower.startsWith('[::1]') || 80 hostLower.startsWith('[0:0:0:0:0:0:0:1]')); 81 } 82 //# sourceMappingURL=proxy.js.map