request: Replace deprecated request module with net.request.

Co-authored-by: Anders Kaseorg <anders@zulip.com>

Fixes: #886.
This commit is contained in:
Manav Mehta
2020-07-14 15:50:52 +05:30
committed by GitHub
parent 9cf26f4890
commit 14a1f5d3e1
12 changed files with 247 additions and 318 deletions

View File

@@ -5,47 +5,6 @@ export interface ProxyRule {
port?: number;
}
// Return proxy to be used for a particular uri, to be used for request
export function getProxy(_uri: string): ProxyRule | undefined {
let uri;
try {
uri = new URL(_uri);
} catch {
return undefined;
}
const proxyRules = ConfigUtil.getConfigItem('proxyRules', '').split(';');
// If SPS is on and system uses no proxy then request should not try to use proxy from
// environment. NO_PROXY = '*' makes request ignore all environment proxy variables.
if (proxyRules[0] === '') {
process.env.NO_PROXY = '*';
return undefined;
}
const proxyRule: any = {};
if (uri.protocol === 'http:') {
proxyRules.forEach((proxy: string) => {
if (proxy.includes('http=')) {
proxyRule.hostname = proxy.split('http=')[1].trim().split(':')[0];
proxyRule.port = proxy.split('http=')[1].trim().split(':')[1];
}
});
return proxyRule;
}
if (uri.protocol === 'https:') {
proxyRules.forEach((proxy: string) => {
if (proxy.includes('https=')) {
proxyRule.hostname = proxy.split('https=')[1].trim().split(':')[0];
proxyRule.port = proxy.split('https=')[1].trim().split(':')[1];
}
});
return proxyRule;
}
return undefined;
}
// TODO: Refactor to async function
export async function resolveSystemProxy(mainWindow: Electron.BrowserWindow): Promise<void> {
const page = mainWindow.webContents;