Merge pull request #602 from glenacota/clean-up-code-spring-cloud-gateway-core
Clean-up core module - against branch 2.0.x
This commit is contained in:
@@ -182,7 +182,7 @@ http POST :8080/admin/gateway/routes/apiaddreqhead uri=http://httpbin.org:80 pre
|
||||
return this.routeDefinitionLocator.getRouteDefinitions()
|
||||
.filter(route -> route.getId().equals(id))
|
||||
.singleOrEmpty()
|
||||
.map(route -> ResponseEntity.ok(route))
|
||||
.map(ResponseEntity::ok)
|
||||
.switchIfEmpty(Mono.just(ResponseEntity.notFound().build()));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class FilterDefinition {
|
||||
}
|
||||
|
||||
public FilterDefinition(String text) {
|
||||
int eqIdx = text.indexOf("=");
|
||||
int eqIdx = text.indexOf('=');
|
||||
if (eqIdx <= 0) {
|
||||
setName(text);
|
||||
return;
|
||||
|
||||
@@ -62,10 +62,6 @@ public interface HttpHeadersFilter {
|
||||
}
|
||||
|
||||
default boolean supports(Type type) {
|
||||
if (type.equals(Type.REQUEST)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return type.equals(Type.REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.springframework.cloud.gateway.handler.predicate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class PredicateDefinition {
|
||||
}
|
||||
|
||||
public PredicateDefinition(String text) {
|
||||
int eqIdx = text.indexOf("=");
|
||||
int eqIdx = text.indexOf('=');
|
||||
if (eqIdx <= 0) {
|
||||
throw new ValidationException("Unable to parse PredicateDefinition text '" + text + "'" +
|
||||
", must be of the form name=value");
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CachingRouteDefinitionLocator implements RouteDefinitionLocator {
|
||||
public CachingRouteDefinitionLocator(RouteDefinitionLocator delegate) {
|
||||
this.delegate = delegate;
|
||||
routeDefinitions = CacheFlux.lookup(cache, "routeDefs", RouteDefinition.class)
|
||||
.onCacheMissResume(() -> this.delegate.getRouteDefinitions());
|
||||
.onCacheMissResume(this.delegate::getRouteDefinitions);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class RouteDefinition {
|
||||
public RouteDefinition() {}
|
||||
|
||||
public RouteDefinition(String text) {
|
||||
int eqIdx = text.indexOf("=");
|
||||
int eqIdx = text.indexOf('=');
|
||||
if (eqIdx <= 0) {
|
||||
throw new ValidationException("Unable to parse RouteDefinition text '" + text + "'" +
|
||||
", must be of the form name=value");
|
||||
|
||||
@@ -556,7 +556,4 @@ public class GatewayFilterSpec extends UriSpec {
|
||||
}));
|
||||
}
|
||||
|
||||
private String routeId() {
|
||||
return routeBuilder.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,15 @@
|
||||
|
||||
package org.springframework.cloud.gateway.support;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.web.reactive.function.server.HandlerStrategies;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseCookie;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
@@ -43,8 +40,6 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
public class DefaultServerResponse<T> implements ServerResponse {
|
||||
|
||||
|
||||
private static final Set<HttpMethod> SAFE_METHODS = EnumSet.of(HttpMethod.GET, HttpMethod.HEAD);
|
||||
|
||||
private final ServerWebExchange exchange;
|
||||
|
||||
private final BodyInserter<T, ? super ServerHttpResponse> inserter;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class XForwardedRemoteAddressResolver implements RemoteAddressResolver {
|
||||
public InetSocketAddress resolve(ServerWebExchange exchange) {
|
||||
List<String> xForwardedValues = extractXForwardedValues(exchange);
|
||||
Collections.reverse(xForwardedValues);
|
||||
if (xForwardedValues.size() != 0) {
|
||||
if (!xForwardedValues.isEmpty()) {
|
||||
int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1;
|
||||
return InetSocketAddress.createUnresolved(xForwardedValues.get(index), 0);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class XForwardedRemoteAddressResolver implements RemoteAddressResolver {
|
||||
private List<String> extractXForwardedValues(ServerWebExchange exchange) {
|
||||
List<String> xForwardedValues = exchange.getRequest().getHeaders()
|
||||
.get(X_FORWARDED_FOR);
|
||||
if (xForwardedValues == null || xForwardedValues.size() == 0) {
|
||||
if (xForwardedValues == null || xForwardedValues.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (xForwardedValues.size() > 1) {
|
||||
|
||||
Reference in New Issue
Block a user