core: remove GrpcUtil.getHost

This utility is not relevant on supported JDK versions anymore.
This commit is contained in:
Benjamin Peterson 2024-06-27 15:20:47 -07:00 committed by Eric Anderson
parent ccfd351a2e
commit 6e25c03a7b
2 changed files with 9 additions and 36 deletions

View File

@ -48,10 +48,8 @@ import io.grpc.internal.StreamListener.MessageProducer;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
@ -632,25 +630,6 @@ public final class GrpcUtil {
}
};
/**
* Returns the host via {@link InetSocketAddress#getHostString} if it is possible,
* i.e. in jdk >= 7.
* Otherwise, return it via {@link InetSocketAddress#getHostName} which may incur a DNS lookup.
*/
public static String getHost(InetSocketAddress addr) {
try {
Method getHostStringMethod = InetSocketAddress.class.getMethod("getHostString");
return (String) getHostStringMethod.invoke(addr);
} catch (NoSuchMethodException e) {
// noop
} catch (IllegalAccessException e) {
// noop
} catch (InvocationTargetException e) {
// noop
}
return addr.getHostName();
}
/**
* Marshals a nanoseconds representation of the timeout to and from a string representation,
* consisting of an ASCII decimal representation of a number with at most 8 digits, followed by a

View File

@ -202,14 +202,7 @@ class ProxyDetectorImpl implements ProxyDetector {
private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IOException {
URI uri;
String host;
try {
host = GrpcUtil.getHost(targetAddr);
} catch (Throwable t) {
// Workaround for Android API levels < 19 if getHostName causes a NetworkOnMainThreadException
log.log(Level.WARNING, "Failed to get host for proxy lookup, proceeding without proxy", t);
return null;
}
String host = targetAddr.getHostString();
try {
uri =
new URI(
@ -247,13 +240,14 @@ class ProxyDetectorImpl implements ProxyDetector {
// The prompt string should be the realm as returned by the server.
// We don't have it because we are avoiding the full handshake.
String promptString = "";
PasswordAuthentication auth = authenticationProvider.requestPasswordAuthentication(
GrpcUtil.getHost(proxyAddr),
proxyAddr.getAddress(),
proxyAddr.getPort(),
PROXY_SCHEME,
promptString,
null);
PasswordAuthentication auth =
authenticationProvider.requestPasswordAuthentication(
proxyAddr.getHostString(),
proxyAddr.getAddress(),
proxyAddr.getPort(),
PROXY_SCHEME,
promptString,
null);
final InetSocketAddress resolvedProxyAddr;
if (proxyAddr.isUnresolved()) {