Lazy import proxy-agent
This commit is contained in:
parent
83e8f4b59d
commit
091b50c414
9 changed files with 60 additions and 39 deletions
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { ProxyAgent } from 'proxy-agent';
|
||||
import net from 'net';
|
||||
import type { ProxyAgent } from 'proxy-agent';
|
||||
import { URL } from 'url';
|
||||
import type { LookupOptions, LookupAddress } from 'dns';
|
||||
import { lookup } from 'dns/promises';
|
||||
|
@ -25,7 +25,9 @@ const SOCKS_PROTOCOLS = new Set([
|
|||
'socks5h:',
|
||||
]);
|
||||
|
||||
export function createProxyAgent(proxyUrl: string): ProxyAgent {
|
||||
export type { ProxyAgent };
|
||||
|
||||
export async function createProxyAgent(proxyUrl: string): Promise<ProxyAgent> {
|
||||
const { port: portStr, hostname: proxyHost, protocol } = new URL(proxyUrl);
|
||||
let defaultPort: number | undefined;
|
||||
if (protocol === 'http:') {
|
||||
|
@ -96,6 +98,8 @@ export function createProxyAgent(proxyUrl: string): ProxyAgent {
|
|||
}
|
||||
}
|
||||
|
||||
const { ProxyAgent } = await import('proxy-agent');
|
||||
|
||||
return new ProxyAgent({
|
||||
lookup:
|
||||
port !== undefined
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue