Skip to content

Commit 276321d

Browse files
committed
feat: support "http_proxy" channel option
1 parent dac1da4 commit 276321d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/grpc-js/src/channel-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface ChannelOptions {
3636
'grpc.max_send_message_length'?: number;
3737
'grpc.max_receive_message_length'?: number;
3838
'grpc.enable_http_proxy'?: number;
39+
'grpc.http_proxy'?: string;
3940
/* http_connect_target and http_connect_creds are used for passing data
4041
* around internally, and should not be documented as public-facing options
4142
*/

packages/grpc-js/src/http_proxy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface ProxyInfo {
4141
creds?: string;
4242
}
4343

44-
function getProxyInfo(): ProxyInfo {
44+
function getProxyInfo(proxy?: string): ProxyInfo {
4545
let proxyEnv = '';
4646
let envVar = '';
4747
/* Prefer using 'grpc_proxy'. Fallback on 'http_proxy' if it is not set.
@@ -57,6 +57,9 @@ function getProxyInfo(): ProxyInfo {
5757
} else if (process.env.http_proxy) {
5858
envVar = 'http_proxy';
5959
proxyEnv = process.env.http_proxy;
60+
} else if(proxy) {
61+
envVar = 'proxy';
62+
proxyEnv = proxy
6063
} else {
6164
return {};
6265
}
@@ -190,7 +193,7 @@ export function mapProxyName(
190193
if (target.scheme === 'unix') {
191194
return noProxyResult;
192195
}
193-
const proxyInfo = getProxyInfo();
196+
const proxyInfo = getProxyInfo(options['grpc.http_proxy']);
194197
if (!proxyInfo.address) {
195198
return noProxyResult;
196199
}

0 commit comments

Comments
 (0)