Reputation: 70
Using grpc from either nodejs or java, what are the properties or configuration necessary to get a grpc client to connect to a server through a proxy?
I have been unable to find either an example or a document explaining the settings. Do I need to do something in the code itself?
I am behind a proxy and I am not sure if the issue is that my settings are incorrect or that my proxy does not support grpc. It supports http/2 as a protocol upgrade.
My proxy settings in java are:
-Dhttp.proxyHost=xxx.xxx.xxx
-Dhttp.proxyPort=8888
-Dhttp.nonProxyHosts="*.nowhere.nothing"
-Dhttps.proxyHost=xxx.xxx.com
-Dhttps.proxyPort=8888
-Dhttps.nonProxyHosts="*.nowhere.nothing"
-Dsocks.proxyHost=xxx.xxx.xxx
-Dsocks.proxyPort=8888
-Dsocks.nonProxyHosts="*.nowhere.nothing"
Upvotes: 2
Views: 5867
Reputation: 16631
If you prefer to not use the global https.proxyHost
, https.proxyPort
properties, you could use the StubSettings
of your client to specify a ChannelConfigurator
. It might then look like this:
InetSocketAddress proxyAddress = new InetSocketAddress("my.proxy.local", 8080);
InstantiatingGrpcChannelProvider transportProvider = SessionsStubSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
return input.proxyDetector(new ProxyDetector() {
@Override
public ProxiedSocketAddress proxyFor(SocketAddress targetServerAddress) throws IOException {
if (!(targetServerAddress instanceof InetSocketAddress) || targetServerAddress == null) {
return null;
}
return HttpConnectProxiedSocketAddress.newBuilder()
.setTargetAddress((InetSocketAddress) targetServerAddress)
.setProxyAddress(proxyAddress)
.build();
}
});
}
})
.build();
and then you could use the stubSettings
bellow to create your GRPC client:
stubSettings = XYZStubSettings.newBuilder().setTransportChannelProvider(transportProvider);
Upvotes: 1
Reputation: 307
In later releases (I think since 1.8.0+) you need:
System.setProperty("http.proxyHost", "http-ip-address-hostname");
System.setProperty("http.proxyPort", "http-port-value");
System.setProperty("https.proxyHost", "https-ip-address-hostname");
System.setProperty("https.proxyPort", "https-port-value");
Upvotes: 1
Reputation: 26464
Since grpc-java 1.0.3 you can specify the environment variable GRPC_PROXY_EXP
with a value in the form host:port
. The "EXP" means experimental, as it will be removed after grpc-java observes the normal Java settings (like https.proxyHost
).
Upvotes: 1