Path: blob/main/extensions/configuration-editing/src/node/net.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Agent, globalAgent } from 'https';6import { URL } from 'url';7import { httpsOverHttp } from 'tunnel';8import { window } from 'vscode';910export const agent = getAgent();1112/**13* Return an https agent for the given proxy URL, or return the14* global https agent if the URL was empty or invalid.15*/16function getAgent(url: string | undefined = process.env.HTTPS_PROXY): Agent {17if (!url) {18return globalAgent;19}20try {21const { hostname, port, username, password } = new URL(url);22const auth = username && password && `${username}:${password}`;23return httpsOverHttp({ proxy: { host: hostname, port, proxyAuth: auth } });24} catch (e) {25window.showErrorMessage(`HTTPS_PROXY environment variable ignored: ${e.message}`);26return globalAgent;27}28}293031