Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,13 @@ sslSocketFactory, hostnameVerifier, sock, getOverridenHost(), getOverridenPort()
private Socket createHttpProxySocket(InetSocketAddress address, InetSocketAddress proxyAddress,
String proxyUsername, String proxyPassword) throws IOException, StatusException {
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);

Source source = Okio.source(sock);
Expand Down
27 changes: 27 additions & 0 deletions okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,33 @@ public void proxy_immediateServerClose() throws Exception {
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
public void goAway_notUtf8() throws Exception {
initTransport();
Expand Down