Socket
Socket
Sign inDemoInstall

vscode-proxy-agent

Package Overview
Dependencies
26
Maintainers
12
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.1 to 0.9.0

out/agent.d.ts

3

CHANGELOG.md
# Change Log
Notable changes will be documented here.
## [0.9.0]
- Copy and adapt pac-proxy-agent to catch up with latest dependencies and bug fixes.
## [0.8.0]

@@ -5,0 +8,0 @@ - Align log level constants with VS Code.

15

out/index.d.ts

@@ -58,17 +58,2 @@ /// <reference types="node" />

declare function useSystemCertificates(params: ProxyAgentParams, useSystemCertificates: boolean, opts: http.RequestOptions, callback: () => void): void;
export interface ProxyAgentOptions {
resolveProxy(req: http.ClientRequest, opts: http.RequestOptions, url: string, callback: (proxy: string | undefined) => void): void;
defaultPort: number;
originalAgent?: http.Agent | false;
}
export declare class ProxyAgent0 {
session: ProxyAgentOptions;
defaultPort: number | undefined;
constructor(session: ProxyAgentOptions);
addRequest: typeof addRequest;
}
declare function addRequest(this: ProxyAgent0, req: http.ClientRequest, opts: http.RequestOptions): void;
export declare const ProxyAgent: {
new (session: ProxyAgentOptions): http.Agent;
};
export {};

@@ -6,13 +6,2 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -46,43 +35,10 @@ if (k2 === undefined) k2 = k;

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyAgent = exports.ProxyAgent0 = exports.createTlsPatch = exports.createHttpPatch = exports.createProxyResolver = exports.LogLevel = void 0;
var http = __importStar(require("http"));
var nodeurl = __importStar(require("url"));
var os = __importStar(require("os"));
var fs = __importStar(require("fs"));
var cp = __importStar(require("child_process"));
var http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
var https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
var debug_1 = __importDefault(require("debug"));
var SocksProxyAgent = require('socks-proxy-agent');
exports.createTlsPatch = exports.createHttpPatch = exports.createProxyResolver = exports.LogLevel = void 0;
const nodeurl = __importStar(require("url"));
const os = __importStar(require("os"));
const fs = __importStar(require("fs"));
const cp = __importStar(require("child_process"));
const agent_1 = __importStar(require("./agent"));
const SocksProxyAgent = require('socks-proxy-agent');
var LogLevel;

@@ -98,16 +54,16 @@ (function (LogLevel) {

})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
var maxCacheEntries = 5000; // Cache can grow twice that much due to 'oldCache'.
const maxCacheEntries = 5000; // Cache can grow twice that much due to 'oldCache'.
function createProxyResolver(params) {
var getHttpProxySetting = params.getHttpProxySetting, log = params.log, getLogLevel = params.getLogLevel, proxyResolverTelemetry = params.proxyResolveTelemetry, useHostProxy = params.useHostProxy, env = params.env;
var envProxy = proxyFromConfigURL(env.https_proxy || env.HTTPS_PROXY || env.http_proxy || env.HTTP_PROXY); // Not standardized.
var envNoProxy = noProxyFromEnv(env.no_proxy || env.NO_PROXY); // Not standardized.
var cacheRolls = 0;
var oldCache = new Map();
var cache = new Map();
const { getHttpProxySetting, log, getLogLevel, proxyResolveTelemetry: proxyResolverTelemetry, useHostProxy, env } = params;
let envProxy = proxyFromConfigURL(env.https_proxy || env.HTTPS_PROXY || env.http_proxy || env.HTTP_PROXY); // Not standardized.
let envNoProxy = noProxyFromEnv(env.no_proxy || env.NO_PROXY); // Not standardized.
let cacheRolls = 0;
let oldCache = new Map();
let cache = new Map();
function getCacheKey(url) {
// Expecting proxies to usually be the same per scheme://host:port. Assuming that for performance.
return nodeurl.format(__assign(__assign({}, url), { pathname: undefined, search: undefined, hash: undefined }));
return nodeurl.format(Object.assign(Object.assign({}, url), { pathname: undefined, search: undefined, hash: undefined }));
}
function getCachedProxy(key) {
var proxy = cache.get(key);
let proxy = cache.get(key);
if (proxy) {

@@ -132,15 +88,15 @@ return proxy;

}
var timeout;
var count = 0;
var duration = 0;
var errorCount = 0;
var cacheCount = 0;
var envCount = 0;
var settingsCount = 0;
var localhostCount = 0;
var envNoProxyCount = 0;
var results = [];
let timeout;
let count = 0;
let duration = 0;
let errorCount = 0;
let cacheCount = 0;
let envCount = 0;
let settingsCount = 0;
let localhostCount = 0;
let envNoProxyCount = 0;
let results = [];
function logEvent() {
timeout = undefined;
proxyResolverTelemetry({ count: count, duration: duration, errorCount: errorCount, cacheCount: cacheCount, cacheSize: cache.size, cacheRolls: cacheRolls, envCount: envCount, settingsCount: settingsCount, localhostCount: localhostCount, envNoProxyCount: envNoProxyCount, results: results });
proxyResolverTelemetry({ count, duration, errorCount, cacheCount, cacheSize: cache.size, cacheRolls, envCount, settingsCount, localhostCount, envNoProxyCount, results });
count = duration = errorCount = cacheCount = envCount = settingsCount = localhostCount = envNoProxyCount = 0;

@@ -153,4 +109,4 @@ results = [];

}
var stackText = getLogLevel() === LogLevel.Trace ? '\n' + new Error('Error for stack trace').stack : '';
useSystemCertificates(params, flags.useSystemCertificates, opts, function () {
const stackText = getLogLevel() === LogLevel.Trace ? '\n' + new Error('Error for stack trace').stack : '';
useSystemCertificates(params, flags.useSystemCertificates, opts, () => {
useProxySettings(useHostProxy, flags.useProxySettings, req, opts, url, stackText, callback);

@@ -164,4 +120,4 @@ });

}
var parsedUrl = nodeurl.parse(url); // Coming from Node's URL, sticking with that.
var hostname = parsedUrl.hostname;
const parsedUrl = nodeurl.parse(url); // Coming from Node's URL, sticking with that.
const hostname = parsedUrl.hostname;
if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' || hostname === '::ffff:127.0.0.1') {

@@ -173,3 +129,5 @@ localhostCount++;

}
if (typeof hostname === 'string' && envNoProxy(hostname, String(parsedUrl.port || opts.agent.defaultPort))) {
const { secureEndpoint } = opts;
const defaultPort = secureEndpoint ? 443 : 80;
if (typeof hostname === 'string' && envNoProxy(hostname, String(parsedUrl.port || defaultPort))) {
envNoProxyCount++;

@@ -180,3 +138,3 @@ callback('DIRECT');

}
var settingsProxy = proxyFromConfigURL(getHttpProxySetting());
let settingsProxy = proxyFromConfigURL(getHttpProxySetting());
if (settingsProxy) {

@@ -194,4 +152,4 @@ settingsCount++;

}
var key = getCacheKey(parsedUrl);
var proxy = getCachedProxy(key);
const key = getCacheKey(parsedUrl);
const proxy = getCachedProxy(key);
if (proxy) {

@@ -209,5 +167,5 @@ cacheCount++;

}
var start = Date.now();
const start = Date.now();
params.resolveProxy(url) // Use full URL to ensure it is an actually used one.
.then(function (proxy) {
.then(proxy => {
if (proxy) {

@@ -219,6 +177,6 @@ cacheProxy(key, proxy);

log(LogLevel.Debug, 'ProxyResolver#resolveProxy', url, proxy, stackText);
}).then(function () {
}).then(() => {
count++;
duration = Date.now() - start + duration;
}, function (err) {
}, err => {
errorCount++;

@@ -233,11 +191,11 @@ callback();

function collectResult(results, resolveProxy, connection, req) {
var proxy = resolveProxy ? String(resolveProxy).trim().split(/\s+/, 1)[0] : 'EMPTY';
req.on('response', function (res) {
var code = "HTTP_" + res.statusCode;
var result = findOrCreateResult(results, proxy, connection, code);
const proxy = resolveProxy ? String(resolveProxy).trim().split(/\s+/, 1)[0] : 'EMPTY';
req.on('response', res => {
const code = `HTTP_${res.statusCode}`;
const result = findOrCreateResult(results, proxy, connection, code);
result.count++;
});
req.on('error', function (err) {
var code = err && typeof err.code === 'string' && err.code || 'UNKNOWN_ERROR';
var result = findOrCreateResult(results, proxy, connection, code);
req.on('error', err => {
const code = err && typeof err.code === 'string' && err.code || 'UNKNOWN_ERROR';
const result = findOrCreateResult(results, proxy, connection, code);
result.count++;

@@ -247,9 +205,8 @@ });

function findOrCreateResult(results, proxy, connection, code) {
for (var _i = 0, results_1 = results; _i < results_1.length; _i++) {
var result_1 = results_1[_i];
if (result_1.proxy === proxy && result_1.connection === connection && result_1.code === code) {
return result_1;
for (const result of results) {
if (result.proxy === proxy && result.connection === connection && result.code === code) {
return result;
}
}
var result = { proxy: proxy, connection: connection, code: code, count: 0 };
const result = { proxy, connection, code, count: 0 };
results.push(result);

@@ -262,9 +219,9 @@ return result;

}
var url = (configURL || '').trim();
var i = url.indexOf('://');
const url = (configURL || '').trim();
const i = url.indexOf('://');
if (i === -1) {
return undefined;
}
var scheme = url.substr(0, i).toLowerCase();
var proxy = url.substr(i + 3);
const scheme = url.substr(0, i).toLowerCase();
const proxy = url.substr(i + 3);
if (scheme === 'http') {

@@ -282,28 +239,23 @@ return 'PROXY ' + proxy;

function noProxyFromEnv(envValue) {
var value = (envValue || '')
const value = (envValue || '')
.trim()
.toLowerCase();
if (value === '*') {
return function () { return true; };
return () => true;
}
var filters = value
const filters = value
.split(',')
.map(function (s) { return s.trim().split(':', 2); })
.map(function (_a) {
var name = _a[0], port = _a[1];
return ({ name: name, port: port });
})
.filter(function (filter) { return !!filter.name; })
.map(function (_a) {
var name = _a.name, port = _a.port;
var domain = name[0] === '.' ? name : "." + name;
return { domain: domain, port: port };
.map(s => s.trim().split(':', 2))
.map(([name, port]) => ({ name, port }))
.filter(filter => !!filter.name)
.map(({ name, port }) => {
const domain = name[0] === '.' ? name : `.${name}`;
return { domain, port };
});
if (!filters.length) {
return function () { return false; };
return () => false;
}
return function (hostname, port) { return filters.some(function (_a) {
var domain = _a.domain, filterPort = _a.port;
return ("." + hostname.toLowerCase()).endsWith(domain) && (!filterPort || port === filterPort);
}); };
return (hostname, port) => filters.some(({ domain, port: filterPort }) => {
return `.${hostname.toLowerCase()}`.endsWith(domain) && (!filterPort || port === filterPort);
});
}

@@ -330,33 +282,30 @@ function createHttpPatch(originals, resolveProxy, proxySetting, certSetting, onRequest) {

}
var originalAgent = options.agent;
const originalAgent = options.agent;
if (originalAgent === true) {
throw new Error('Unexpected agent option: true');
}
var isHttps = originals.globalAgent.protocol === 'https:';
var optionsPatched = originalAgent instanceof exports.ProxyAgent;
var config = onRequest && (options._vscodeProxySupport || /* LS */ options._vscodeSystemProxy) || proxySetting.config;
var useProxySettings = !optionsPatched && (config === 'override' || config === 'on' && originalAgent === undefined);
var useSystemCertificates = !optionsPatched && certSetting.config && isHttps && !options.ca;
const isHttps = originals.globalAgent.protocol === 'https:';
const optionsPatched = originalAgent instanceof agent_1.PacProxyAgent;
const config = onRequest && (options._vscodeProxySupport || /* LS */ options._vscodeSystemProxy) || proxySetting.config;
const useProxySettings = !optionsPatched && (config === 'override' || config === 'on' && originalAgent === undefined);
const useSystemCertificates = !optionsPatched && certSetting.config && isHttps && !options.ca;
if (useProxySettings || useSystemCertificates) {
if (url) {
var parsed = typeof url === 'string' ? new nodeurl.URL(url) : url;
var urlOptions = {
const parsed = typeof url === 'string' ? new nodeurl.URL(url) : url;
const urlOptions = {
protocol: parsed.protocol,
hostname: parsed.hostname.lastIndexOf('[', 0) === 0 ? parsed.hostname.slice(1, -1) : parsed.hostname,
port: parsed.port,
path: "" + parsed.pathname + parsed.search
path: `${parsed.pathname}${parsed.search}`
};
if (parsed.username || parsed.password) {
options.auth = parsed.username + ":" + parsed.password;
options.auth = `${parsed.username}:${parsed.password}`;
}
options = __assign(__assign({}, urlOptions), options);
options = Object.assign(Object.assign({}, urlOptions), options);
}
else {
options = __assign({}, options);
options = Object.assign({}, options);
}
options.agent = new exports.ProxyAgent({
resolveProxy: resolveProxy.bind(undefined, { useProxySettings: useProxySettings, useSystemCertificates: useSystemCertificates }),
defaultPort: isHttps ? 443 : 80,
originalAgent: !useProxySettings ? originalAgent : undefined,
});
const resolveP = (req, opts, url) => new Promise(resolve => resolveProxy({ useProxySettings, useSystemCertificates }, req, opts, url, resolve));
options.agent = agent_1.default(resolveP, { originalAgent: !useProxySettings ? originalAgent : undefined });
return original(options, callback);

@@ -376,7 +325,6 @@ }

return function (details) {
var context = original.apply(null, arguments);
var certs = details._vscodeAdditionalCaCerts;
const context = original.apply(null, arguments);
const certs = details._vscodeAdditionalCaCerts;
if (certs) {
for (var _i = 0, certs_1 = certs; _i < certs_1.length; _i++) {
var cert = certs_1[_i];
for (const cert of certs) {
context.context.addCACert(cert);

@@ -393,3 +341,3 @@ }

getCaCertificates(params)
.then(function (caCertificates) {
.then(caCertificates => {
if (caCertificates) {

@@ -405,3 +353,3 @@ if (caCertificates.append) {

})
.catch(function (err) {
.catch(err => {
params.log(LogLevel.Error, 'ProxyResolver#useSystemCertificates', toErrorMessage(err));

@@ -414,92 +362,74 @@ });

}
var _caCertificates;
function getCaCertificates(_a) {
var log = _a.log;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_b) {
if (!_caCertificates) {
_caCertificates = readCaCertificates()
.then(function (res) {
log(LogLevel.Debug, 'ProxyResolver#getCaCertificates count', res && res.certs.length);
return res && res.certs.length ? res : undefined;
})
.catch(function (err) {
log(LogLevel.Error, 'ProxyResolver#getCaCertificates error', toErrorMessage(err));
return undefined;
});
}
return [2 /*return*/, _caCertificates];
});
let _caCertificates;
function getCaCertificates({ log }) {
return __awaiter(this, void 0, void 0, function* () {
if (!_caCertificates) {
_caCertificates = readCaCertificates()
.then(res => {
log(LogLevel.Debug, 'ProxyResolver#getCaCertificates count', res && res.certs.length);
return res && res.certs.length ? res : undefined;
})
.catch(err => {
log(LogLevel.Error, 'ProxyResolver#getCaCertificates error', toErrorMessage(err));
return undefined;
});
}
return _caCertificates;
});
}
function readCaCertificates() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (process.platform === 'win32') {
return [2 /*return*/, readWindowsCaCertificates()];
}
if (process.platform === 'darwin') {
return [2 /*return*/, readMacCaCertificates()];
}
if (process.platform === 'linux') {
return [2 /*return*/, readLinuxCaCertificates()];
}
return [2 /*return*/, undefined];
});
return __awaiter(this, void 0, void 0, function* () {
if (process.platform === 'win32') {
return readWindowsCaCertificates();
}
if (process.platform === 'darwin') {
return readMacCaCertificates();
}
if (process.platform === 'linux') {
return readLinuxCaCertificates();
}
return undefined;
});
}
function readWindowsCaCertificates() {
return __awaiter(this, void 0, void 0, function () {
var winCA, ders, store, der, certs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('vscode-windows-ca-certs')); })];
case 1:
winCA = _a.sent();
ders = [];
store = new winCA.Crypt32();
try {
der = void 0;
while (der = store.next()) {
ders.push(der);
}
}
finally {
store.done();
}
certs = new Set(ders.map(derToPem));
return [2 /*return*/, {
certs: Array.from(certs),
append: true
}];
return __awaiter(this, void 0, void 0, function* () {
// @ts-ignore Windows only
const winCA = yield Promise.resolve().then(() => __importStar(require('vscode-windows-ca-certs')));
let ders = [];
const store = new winCA.Crypt32();
try {
let der;
while (der = store.next()) {
ders.push(der);
}
});
}
finally {
store.done();
}
const certs = new Set(ders.map(derToPem));
return {
certs: Array.from(certs),
append: true
};
});
}
function readMacCaCertificates() {
return __awaiter(this, void 0, void 0, function () {
var stdout, certs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
var child = cp.spawn('/usr/bin/security', ['find-certificate', '-a', '-p']);
var stdout = [];
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (str) { return stdout.push(str); });
child.on('error', reject);
child.on('exit', function (code) { return code ? reject(code) : resolve(stdout.join('')); });
})];
case 1:
stdout = _a.sent();
certs = new Set(stdout.split(/(?=-----BEGIN CERTIFICATE-----)/g)
.filter(function (pem) { return !!pem.length; }));
return [2 /*return*/, {
certs: Array.from(certs),
append: true
}];
}
return __awaiter(this, void 0, void 0, function* () {
const stdout = yield new Promise((resolve, reject) => {
const child = cp.spawn('/usr/bin/security', ['find-certificate', '-a', '-p']);
const stdout = [];
child.stdout.setEncoding('utf8');
child.stdout.on('data', str => stdout.push(str));
child.on('error', reject);
child.on('exit', code => code ? reject(code) : resolve(stdout.join('')));
});
const certs = new Set(stdout.split(/(?=-----BEGIN CERTIFICATE-----)/g)
.filter(pem => !!pem.length));
return {
certs: Array.from(certs),
append: true
};
});
}
var linuxCaCertificatePaths = [
const linuxCaCertificatePaths = [
'/etc/ssl/certs/ca-certificates.crt',

@@ -509,42 +439,26 @@ '/etc/ssl/certs/ca-bundle.crt',

function readLinuxCaCertificates() {
return __awaiter(this, void 0, void 0, function () {
var _i, linuxCaCertificatePaths_1, certPath, content, certs, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_i = 0, linuxCaCertificatePaths_1 = linuxCaCertificatePaths;
_a.label = 1;
case 1:
if (!(_i < linuxCaCertificatePaths_1.length)) return [3 /*break*/, 6];
certPath = linuxCaCertificatePaths_1[_i];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, fs.promises.readFile(certPath, { encoding: 'utf8' })];
case 3:
content = _a.sent();
certs = new Set(content.split(/(?=-----BEGIN CERTIFICATE-----)/g)
.filter(function (pem) { return !!pem.length; }));
return [2 /*return*/, {
certs: Array.from(certs),
append: false
}];
case 4:
err_1 = _a.sent();
if (err_1.code !== 'ENOENT') {
throw err_1;
}
return [3 /*break*/, 5];
case 5:
_i++;
return [3 /*break*/, 1];
case 6: return [2 /*return*/, undefined];
return __awaiter(this, void 0, void 0, function* () {
for (const certPath of linuxCaCertificatePaths) {
try {
const content = yield fs.promises.readFile(certPath, { encoding: 'utf8' });
const certs = new Set(content.split(/(?=-----BEGIN CERTIFICATE-----)/g)
.filter(pem => !!pem.length));
return {
certs: Array.from(certs),
append: false
};
}
});
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}
return undefined;
});
}
function derToPem(blob) {
var lines = ['-----BEGIN CERTIFICATE-----'];
var der = blob.toString('base64');
for (var i = 0; i < der.length; i += 64) {
const lines = ['-----BEGIN CERTIFICATE-----'];
const der = blob.toString('base64');
for (let i = 0; i < der.length; i += 64) {
lines.push(der.substr(i, 64));

@@ -558,84 +472,2 @@ }

}
var debugLog = debug_1.default('vscode-proxy-agent');
var ProxyAgent0 = /** @class */ (function () {
function ProxyAgent0(session) {
this.session = session;
this.addRequest = addRequest;
if (!(this instanceof ProxyAgent0))
return new ProxyAgent0(session);
this.defaultPort = session.defaultPort;
}
return ProxyAgent0;
}());
exports.ProxyAgent0 = ProxyAgent0;
function addRequest(req, opts) {
var url;
var self = this;
// calculate the `url` parameter
var defaultAgent = opts._defaultAgent || http.globalAgent;
var path = req.path;
var firstQuestion = path.indexOf('?');
var search;
if (-1 != firstQuestion) {
search = path.substring(firstQuestion);
path = path.substring(0, firstQuestion);
}
url = nodeurl.format(Object.assign({}, opts, {
protocol: defaultAgent.protocol,
pathname: path,
search: search,
// need to use `hostname` instead of `host` otherwise `port` is ignored
hostname: opts.host,
host: null,
// set `port` to null when it is the protocol default port (80 / 443)
port: defaultAgent.defaultPort == opts.port ? null : opts.port
}));
debugLog('url: %o', url);
self.session.resolveProxy(req, opts, url, onproxy);
// `resolveProxy()` callback function
function onproxy(proxy) {
// default to "DIRECT" if a falsey value was returned (or nothing)
if (!proxy)
proxy = 'DIRECT';
var proxies = String(proxy).trim().split(/\s*;\s*/g).filter(Boolean);
// XXX: right now, only the first proxy specified will be used
var first = proxies[0];
debugLog('using proxy: %o', first);
var agent;
var parts = first.split(/\s+/);
var type = parts[0];
if ('DIRECT' == type) {
// direct connection to the destination endpoint
agent = getDirectAgent(self.session.originalAgent, defaultAgent);
}
else if ('SOCKS' == type) {
// use a SOCKS proxy
agent = new SocksProxyAgent('socks://' + parts[1]);
}
else if ('PROXY' == type || 'HTTPS' == type) {
// use an HTTP or HTTPS proxy
// http://dev.chromium.org/developers/design-documents/secure-web-proxy
var proxyURL = ('HTTPS' === type ? 'https' : 'http') + '://' + parts[1];
var proxy_1 = nodeurl.parse(proxyURL);
if (defaultAgent.protocol === 'https:') {
agent = new https_proxy_agent_1.default(proxy_1);
}
else {
agent = new http_proxy_agent_1.default(proxy_1);
}
}
else {
// direct connection to the destination endpoint
agent = getDirectAgent(self.session.originalAgent, defaultAgent);
}
agent.addRequest(req, opts);
}
}
function getDirectAgent(originalAgent, defaultAgent) {
if (originalAgent === false) {
return new defaultAgent.constructor();
}
return originalAgent || defaultAgent;
}
exports.ProxyAgent = ProxyAgent0;
//# sourceMappingURL=index.js.map
{
"name": "vscode-proxy-agent",
"version": "0.8.1",
"version": "0.9.0",
"description": "NodeJS http(s) agent implementation for VS Code",

@@ -31,10 +31,12 @@ "main": "out/index.js",

"dependencies": {
"debug": "^3.1.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.3",
"socks-proxy-agent": "^4.0.1"
"@tootallnate/once": "^1.1.2",
"agent-base": "^6.0.2",
"debug": "^4.3.1",
"get-uri": "^3.0.2",
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"socks-proxy-agent": "^5.0.0"
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/http-proxy-agent": "^2.0.2",
"@types/node": "^12.18.3",

@@ -41,0 +43,0 @@ "typescript": "^4.2.2"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc