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