feat: support "http_proxy" channel option

This commit is contained in:
notsapinho 2025-11-21 16:55:38 -03:00
parent dac1da47a8
commit 276321de66
2 changed files with 6 additions and 2 deletions

View File

@ -36,6 +36,7 @@ export interface ChannelOptions {
'grpc.max_send_message_length'?: number;
'grpc.max_receive_message_length'?: number;
'grpc.enable_http_proxy'?: number;
'grpc.http_proxy'?: string;
/* http_connect_target and http_connect_creds are used for passing data
* around internally, and should not be documented as public-facing options
*/

View File

@ -41,7 +41,7 @@ interface ProxyInfo {
creds?: string;
}
function getProxyInfo(): ProxyInfo {
function getProxyInfo(proxy?: string): ProxyInfo {
let proxyEnv = '';
let envVar = '';
/* Prefer using 'grpc_proxy'. Fallback on 'http_proxy' if it is not set.
@ -57,6 +57,9 @@ function getProxyInfo(): ProxyInfo {
} else if (process.env.http_proxy) {
envVar = 'http_proxy';
proxyEnv = process.env.http_proxy;
} else if(proxy) {
envVar = 'proxy';
proxyEnv = proxy
} else {
return {};
}
@ -190,7 +193,7 @@ export function mapProxyName(
if (target.scheme === 'unix') {
return noProxyResult;
}
const proxyInfo = getProxyInfo();
const proxyInfo = getProxyInfo(options['grpc.http_proxy']);
if (!proxyInfo.address) {
return noProxyResult;
}