diff --git a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/common/AbstractGatewayDiscoverer.java b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/common/AbstractGatewayDiscoverer.java index 0021181daa..9d20f4ca1e 100644 --- a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/common/AbstractGatewayDiscoverer.java +++ b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/common/AbstractGatewayDiscoverer.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.function.BiPredicate; import java.util.function.Supplier; import org.apache.commons.logging.Log; @@ -38,6 +39,8 @@ public abstract class AbstractGatewayDiscoverer { protected volatile MultiValueMap operations = new LinkedMultiValueMap<>(); + private final BiPredicate> returnTypePredicate = (method, returnType) -> returnType.isAssignableFrom(method.getReturnType()); + public >, R> void doDiscover(Class supplierClass, Class returnType) { List suppliers = loadSuppliers(supplierClass); @@ -59,8 +62,7 @@ else if (log.isTraceEnabled()) { } for (Method method : methods) { - // TODO: replace with a BiPredicate of some kind - if (returnType.isAssignableFrom(method.getReturnType())) { + if (returnTypePredicate.test(method, returnType)) { addOperationMethod(method); } } diff --git a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java index ab6d47dc94..4a81d5ce0f 100644 --- a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java +++ b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java @@ -147,6 +147,8 @@ static class DelegatingServiceInstance implements ServiceInstance { private String overrideScheme; + private static final Set SECURE_SCHEMES = Set.of("https", "wss"); + DelegatingServiceInstance(ServiceInstance delegate, String overrideScheme) { this.delegate = delegate; this.overrideScheme = overrideScheme; @@ -169,8 +171,7 @@ public int getPort() { @Override public boolean isSecure() { - // TODO: move to map - if ("https".equals(this.overrideScheme) || "wss".equals(this.overrideScheme)) { + if (SECURE_SCHEMES.contains(this.overrideScheme)) { return true; } return delegate.isSecure();