mirror of https://github.com/grpc/grpc-java.git
core,okhttp: handle unresolved proxy addresses
This commit is contained in:
parent
4db323c5c4
commit
4d35ea05c4
|
|
@ -184,7 +184,8 @@ class ProxyDetectorImpl implements ProxyDetector {
|
||||||
+ "be removed in a future release. Use the JVM flags "
|
+ "be removed in a future release. Use the JVM flags "
|
||||||
+ "\"-Dhttps.proxyHost=HOST -Dhttps.proxyPort=PORT\" to set the https proxy for "
|
+ "\"-Dhttps.proxyHost=HOST -Dhttps.proxyPort=PORT\" to set the https proxy for "
|
||||||
+ "this JVM.");
|
+ "this JVM.");
|
||||||
return new InetSocketAddress(parts[0], port);
|
// Return an unresolved InetSocketAddress to avoid DNS lookup
|
||||||
|
return InetSocketAddress.createUnresolved(parts[0], port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -472,7 +472,13 @@ class OkHttpClientTransport implements ConnectionClientTransport {
|
||||||
private Socket createHttpProxySocket(InetSocketAddress address, InetSocketAddress proxyAddress,
|
private Socket createHttpProxySocket(InetSocketAddress address, InetSocketAddress proxyAddress,
|
||||||
String proxyUsername, String proxyPassword) throws IOException, StatusException {
|
String proxyUsername, String proxyPassword) throws IOException, StatusException {
|
||||||
try {
|
try {
|
||||||
Socket sock = new Socket(proxyAddress.getAddress(), proxyAddress.getPort());
|
Socket sock;
|
||||||
|
// The proxy address may not be resolved
|
||||||
|
if (proxyAddress.getAddress() != null) {
|
||||||
|
sock = new Socket(proxyAddress.getAddress(), proxyAddress.getPort());
|
||||||
|
} else {
|
||||||
|
sock = new Socket(proxyAddress.getHostName(), proxyAddress.getPort());
|
||||||
|
}
|
||||||
sock.setTcpNoDelay(true);
|
sock.setTcpNoDelay(true);
|
||||||
|
|
||||||
Source source = Okio.source(sock);
|
Source source = Okio.source(sock);
|
||||||
|
|
|
||||||
|
|
@ -1569,6 +1569,33 @@ public class OkHttpClientTransportTest {
|
||||||
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
|
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void proxy_unresolvedProxyAddress() throws Exception {
|
||||||
|
clientTransport = new OkHttpClientTransport(
|
||||||
|
InetSocketAddress.createUnresolved("theservice", 80),
|
||||||
|
"authority",
|
||||||
|
"userAgent",
|
||||||
|
executor,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
ConnectionSpec.CLEARTEXT,
|
||||||
|
DEFAULT_MAX_MESSAGE_SIZE,
|
||||||
|
InetSocketAddress.createUnresolved("unresolvedproxy", 80),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
tooManyPingsRunnable);
|
||||||
|
clientTransport.start(transportListener);
|
||||||
|
|
||||||
|
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
|
||||||
|
verify(transportListener, timeout(TIME_OUT_MS)).transportShutdown(captor.capture());
|
||||||
|
Status error = captor.getValue();
|
||||||
|
assertTrue("Status didn't contain proxy: " + captor.getValue(),
|
||||||
|
error.getDescription().contains("proxy"));
|
||||||
|
assertEquals("Not UNAVAILABLE: " + captor.getValue(),
|
||||||
|
Status.UNAVAILABLE.getCode(), error.getCode());
|
||||||
|
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void goAway_notUtf8() throws Exception {
|
public void goAway_notUtf8() throws Exception {
|
||||||
initTransport();
|
initTransport();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue