use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.
the class ProxyDetectorImplTest method override_hostOnly.
@Test
public void override_hostOnly() throws Exception {
final String overrideHostWithoutPort = "10.99.99.99";
final int defaultPort = 80;
ProxyDetectorImpl proxyDetector = new ProxyDetectorImpl(proxySelectorSupplier, authenticator, overrideHostWithoutPort);
ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
assertNotNull(detected);
assertEquals(HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(destination).setProxyAddress(new InetSocketAddress(InetAddress.getByName(overrideHostWithoutPort), defaultPort)).build(), detected);
}
use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.
the class ProxyDetectorImplTest method override_hostPort.
@Test
public void override_hostPort() throws Exception {
final String overrideHost = "10.99.99.99";
final int overridePort = 1234;
final String overrideHostWithPort = overrideHost + ":" + overridePort;
ProxyDetectorImpl proxyDetector = new ProxyDetectorImpl(proxySelectorSupplier, authenticator, overrideHostWithPort);
ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
assertNotNull(detected);
assertEquals(HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(destination).setProxyAddress(new InetSocketAddress(InetAddress.getByName(overrideHost), overridePort)).build(), detected);
}
use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.
the class ManagedChannelImplTest method nameResolverArgsPropagation.
@Test
public void nameResolverArgsPropagation() {
final AtomicReference<NameResolver.Args> capturedArgs = new AtomicReference<>();
final NameResolver noopResolver = new NameResolver() {
@Override
public String getServiceAuthority() {
return "fake-authority";
}
@Override
public void start(Listener2 listener) {
}
@Override
public void shutdown() {
}
};
ProxyDetector neverProxy = new ProxyDetector() {
@Override
public ProxiedSocketAddress proxyFor(SocketAddress targetAddress) {
return null;
}
};
NameResolver.Factory factory = new NameResolver.Factory() {
@Override
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
capturedArgs.set(args);
return noopResolver;
}
@Override
public String getDefaultScheme() {
return "fakescheme";
}
};
channelBuilder.nameResolverFactory(factory).proxyDetector(neverProxy);
createChannel();
NameResolver.Args args = capturedArgs.get();
assertThat(args).isNotNull();
assertThat(args.getDefaultPort()).isEqualTo(DEFAULT_PORT);
assertThat(args.getProxyDetector()).isSameInstanceAs(neverProxy);
verify(offloadExecutor, never()).execute(any(Runnable.class));
args.getOffloadExecutor().execute(new Runnable() {
@Override
public void run() {
}
});
verify(offloadExecutor, times(1)).execute(any(Runnable.class));
}
use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.
the class DnsNameResolver method detectProxy.
@Nullable
private EquivalentAddressGroup detectProxy() throws IOException {
InetSocketAddress destination = InetSocketAddress.createUnresolved(host, port);
ProxiedSocketAddress proxiedAddr = proxyDetector.proxyFor(destination);
if (proxiedAddr != null) {
return new EquivalentAddressGroup(proxiedAddr);
}
return null;
}
use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.
the class ProxyDetectorImplTest method detectProxyForUnresolvedDestination.
@Test
public void detectProxyForUnresolvedDestination() throws Exception {
Proxy proxy = new Proxy(Proxy.Type.HTTP, unresolvedProxy);
when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
assertNotNull(detected);
assertEquals(proxySocketAddress, detected);
}
Aggregations