Add setting to set a default proxy for all URLs

This commit is contained in:
pvs 2022-01-02 11:02:53 -08:00
parent 3966eaa3b8
commit 8dcc709b98
2 changed files with 14 additions and 1 deletions

View file

@ -543,6 +543,11 @@ export class default_config {
// "youtube.com": "google",
})
/**
* Default proxy to use for all URLs. Has to be the name of a proxy. To add a proxy, see `:help proxyadd`.
*/
proxy = ""
/**
* Definitions of proxies.
*

View file

@ -108,9 +108,17 @@ const getProxiesForUrl = async (url: string): Promise<ProxyInfo[]> => {
const aucon = new AutoContain()
const [, containerProxies] = await aucon.getAuconAndProxiesForUrl(url)
const proxies = await getProxies()
return Object.entries(proxies)
const filteredProxies = Object.entries(proxies)
.filter(([name, ]) => containerProxies.includes(name))
.map(([, proxy]) => proxy)
const defaultProxy = await config.getAsync("proxy")
if (
defaultProxy in proxies &&
!containerProxies.includes(defaultProxy)
) {
filteredProxies.push(proxies[defaultProxy])
}
return filteredProxies
}
export const onRequestListener = async (