Browse Source

polish

pull/41/head
Spencer Gibb 8 years ago
parent
commit
0c30f7ee83
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayProperties.java
  2. 8
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java
  3. 13
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java
  4. 10
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java
  5. 1
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/support/ExchangeServerRequest.java

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayProperties.java

@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.gateway.model.FilterDefinition;
import org.springframework.cloud.gateway.model.RouteDefinition;
import org.springframework.cloud.gateway.filter.factory.RemoveNonProxyHeadersWebFilterFactory;
import org.springframework.validation.annotation.Validated;
import static org.springframework.cloud.gateway.support.NameUtils.normalizeFilterName;
@ -34,6 +35,7 @@ import static org.springframework.cloud.gateway.support.NameUtils.normalizeFilte @@ -34,6 +35,7 @@ import static org.springframework.cloud.gateway.support.NameUtils.normalizeFilte
* @author Spencer Gibb
*/
@ConfigurationProperties("spring.cloud.gateway")
@Validated
public class GatewayProperties {
/**

8
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/CookieRequestPredicateFactory.java

@ -19,11 +19,12 @@ package org.springframework.cloud.gateway.handler.predicate; @@ -19,11 +19,12 @@ package org.springframework.cloud.gateway.handler.predicate;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.springframework.cloud.gateway.handler.support.ExchangeServerRequest;
import org.springframework.http.HttpCookie;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
@ -44,9 +45,8 @@ public class CookieRequestPredicateFactory implements RequestPredicateFactory { @@ -44,9 +45,8 @@ public class CookieRequestPredicateFactory implements RequestPredicateFactory {
String regexp = args.getString(REGEXP_KEY);
return request -> {
//TODO: bad cast?
ExchangeServerRequest req = (ExchangeServerRequest) request;
List<HttpCookie> cookies = req.exchange().getRequest().getCookies().get(name);
Optional<ServerWebExchange> exchange = request.attribute("exchange");
List<HttpCookie> cookies = exchange.get().getRequest().getCookies().get(name);
for (HttpCookie cookie : cookies) {
if (cookie.getValue().matches(regexp)) {
return true;

13
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRequestPredicateFactory.java

@ -17,13 +17,14 @@ @@ -17,13 +17,14 @@
package org.springframework.cloud.gateway.handler.predicate;
import org.springframework.cloud.gateway.handler.support.ExchangeServerRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.springframework.tuple.Tuple;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.reactive.function.server.RequestPredicates;
import java.util.Arrays;
import java.util.List;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
@ -51,8 +52,8 @@ public class QueryRequestPredicateFactory implements RequestPredicateFactory { @@ -51,8 +52,8 @@ public class QueryRequestPredicateFactory implements RequestPredicateFactory {
if (!args.hasFieldName(REGEXP_KEY)) {
return req -> {
//TODO: ServerRequest support for query params with no value
ExchangeServerRequest request = (ExchangeServerRequest) req;
return request.exchange().getRequest().getQueryParams().containsKey(param);
Optional<ServerWebExchange> exchange = req.attribute("exchange");
return exchange.get().getRequest().getQueryParams().containsKey(param);
};
}

10
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRequestPredicateFactory.java

@ -26,8 +26,8 @@ import org.apache.commons.logging.Log; @@ -26,8 +26,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.gateway.support.SubnetUtils;
import org.springframework.tuple.Tuple;
import org.springframework.cloud.gateway.handler.support.ExchangeServerRequest;
import org.springframework.web.reactive.function.server.RequestPredicate;
import org.springframework.web.server.ServerWebExchange;
/**
* @author Spencer Gibb
@ -47,12 +47,12 @@ public class RemoteAddrRequestPredicateFactory implements RequestPredicateFactor @@ -47,12 +47,12 @@ public class RemoteAddrRequestPredicateFactory implements RequestPredicateFactor
}
}
return req -> {
ExchangeServerRequest serverRequest = (ExchangeServerRequest) req;
Optional<InetSocketAddress> remoteAddress = serverRequest.exchange().getRequest().getRemoteAddress();
return request -> {
Optional<ServerWebExchange> exchange = request.attribute("exchange");
Optional<InetSocketAddress> remoteAddress = exchange.get().getRequest().getRemoteAddress();
if (remoteAddress.isPresent()) {
String hostAddress = remoteAddress.get().getAddress().getHostAddress();
String host = req.uri().getHost();
String host = request.uri().getHost();
if (!hostAddress.equals(host)) {
log.warn("Remote addresses didn't match " + hostAddress + " != " + host);

1
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/support/ExchangeServerRequest.java

@ -78,6 +78,7 @@ public class ExchangeServerRequest implements ServerRequest { @@ -78,6 +78,7 @@ public class ExchangeServerRequest implements ServerRequest {
this.exchange = exchange;
this.strategies = strategies;
this.headers = new ExchangeServerRequest.DefaultHeaders();
this.exchange.getAttributes().put("exchange", this.exchange);
}

Loading…
Cancel
Save