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.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; 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, * 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 * 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 { private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IOException {
URI uri; URI uri;
String host; String host = targetAddr.getHostString();
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;
}
try { try {
uri = uri =
new URI( new URI(
@ -247,8 +240,9 @@ class ProxyDetectorImpl implements ProxyDetector {
// The prompt string should be the realm as returned by the server. // The prompt string should be the realm as returned by the server.
// We don't have it because we are avoiding the full handshake. // We don't have it because we are avoiding the full handshake.
String promptString = ""; String promptString = "";
PasswordAuthentication auth = authenticationProvider.requestPasswordAuthentication( PasswordAuthentication auth =
GrpcUtil.getHost(proxyAddr), authenticationProvider.requestPasswordAuthentication(
proxyAddr.getHostString(),
proxyAddr.getAddress(), proxyAddr.getAddress(),
proxyAddr.getPort(), proxyAddr.getPort(),
PROXY_SCHEME, PROXY_SCHEME,