mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-19 06:39:55 +01:00
d4ab1fcda5
* Fixes more node 12 typing errors For #82514 * Remove Symbol.toStringTag usage for now * Reverting a few fixes that are not comptible with current node typings * Revert one more use of StringDecoder Must wait until we actually pick up the new typings
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { Url, parse as parseUrl } from 'url';
|
|
import { isBoolean } from 'vs/base/common/types';
|
|
|
|
export type Agent = any;
|
|
|
|
function getSystemProxyURI(requestURL: Url): string | null {
|
|
if (requestURL.protocol === 'http:') {
|
|
return process.env.HTTP_PROXY || process.env.http_proxy || null;
|
|
} else if (requestURL.protocol === 'https:') {
|
|
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export interface IOptions {
|
|
proxyUrl?: string;
|
|
strictSSL?: boolean;
|
|
}
|
|
|
|
export async function getProxyAgent(rawRequestURL: string, options: IOptions = {}): Promise<Agent> {
|
|
const requestURL = parseUrl(rawRequestURL);
|
|
const proxyURL = options.proxyUrl || getSystemProxyURI(requestURL);
|
|
|
|
if (!proxyURL) {
|
|
return null;
|
|
}
|
|
|
|
const proxyEndpoint = parseUrl(proxyURL);
|
|
|
|
if (!/^https?:$/.test(proxyEndpoint.protocol || '')) {
|
|
return null;
|
|
}
|
|
|
|
const opts = {
|
|
host: proxyEndpoint.hostname || '',
|
|
port: proxyEndpoint.port || (proxyEndpoint.protocol === 'https' ? '443' : '80'),
|
|
auth: proxyEndpoint.auth,
|
|
rejectUnauthorized: isBoolean(options.strictSSL) ? options.strictSSL : true,
|
|
};
|
|
|
|
return requestURL.protocol === 'http:'
|
|
? new (await import('http-proxy-agent'))(opts as any as Url)
|
|
: new (await import('https-proxy-agent'))(opts);
|
|
}
|