Prompt
Ensure proxy configuration follows proper precedence hierarchy and handles different proxy types correctly. User-specified proxy settings should always take priority over environment variables, similar to how browsers handle proxy configuration.
When implementing proxy support:
- Prioritize user configuration over environment variables:
getProxyAgent(host: string, port: number) { const proxyFromEnv = getProxyForUrl(`https://${host}:${port}`); if (proxyFromEnv) return createProxyAgent({ server: proxyFromEnv }); return createProxyAgent(this._proxy); // User config takes precedence } - Map proxy protocols correctly - use
sslProxyfor HTTPS connections, nothttpsProxy:switch (url.protocol) { case 'http:': proxy.httpProxy = url.host; break; case 'https:': proxy.sslProxy = url.host; // Not httpsProxy break; } - Handle legacy URL formats gracefully while planning migration to modern URL objects:
// TODO: switch to URL instance instead of legacy object once https-proxy-agent supports it. return new HttpsProxyAgent(convertURLtoLegacyUrl(proxyOpts)); - Consider localhost proxy behavior - some environments require explicit configuration to proxy localhost traffic, which should be handled appropriately for testing scenarios.
This approach ensures consistent proxy behavior across different network scenarios and maintains compatibility with existing proxy infrastructure while preparing for future modernization.