mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-03 05:23:17 +00:00
request: Replace deprecated request module with net.request.
Co-authored-by: Anders Kaseorg <anders@zulip.com> Fixes: #886.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user