UNPKG

hfs

Version:
44 lines (43 loc) 1.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("./config"); const node_url_1 = require("node:url"); const util_http_1 = require("./util-http"); const util_os_1 = require("./util-os"); const events_1 = __importDefault(require("./events")); const const_1 = require("./const"); const cross_1 = require("./cross"); // don't move this in util-http, where it would mostly belong, as a require to config.ts would prevent tests using util-http const outboundProxy = (0, config_1.defineConfig)('outbound_proxy', '', v => { try { (0, node_url_1.parse)(v); util_http_1.httpStream.defaultProxy = v; } catch (_a) { console.warn("invalid URL", v); return ''; } }); events_1.default.once('configReady', async (startedWithoutConfig) => { var _a, _b, _c, _d; if (!const_1.IS_WINDOWS || !startedWithoutConfig) return; // try to read Windows system setting for proxy const out = await (0, util_os_1.reg)('query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'); if (!((_a = /ProxyEnable.+(\d)/.exec(out)) === null || _a === void 0 ? void 0 : _a[1])) return; const read = (_b = /ProxyServer.+?([\d:.]+)/.exec(out)) === null || _b === void 0 ? void 0 : _b[1]; if (!read) return; // it can be like "IP:PORT" or "http=IP:PORT;https=IP:PORT;ftp=IP:PORT" const url = (0, cross_1.prefix)('https://', (_c = /https=([\d:.]+)/.exec(out)) === null || _c === void 0 ? void 0 : _c[1]) // prefer https || (0, cross_1.prefix)('http://', (_d = /http=([\d:.]+)/.exec(out)) === null || _d === void 0 ? void 0 : _d[1]) || !read.includes('=') && 'http://' + read; // simpler form if (!url) return; outboundProxy.set(url); console.log("detected proxy", read); });