This commit is contained in:
Spencer Gibb
2017-03-17 16:30:14 -06:00
parent d42ac55029
commit 0c30f7ee83
5 changed files with 19 additions and 15 deletions

View File

@@ -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
* @author Spencer Gibb
*/
@ConfigurationProperties("spring.cloud.gateway")
@Validated
public class GatewayProperties {
/**

View File

@@ -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 {
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;

View File

@@ -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 {
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);
};
}

View File

@@ -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
}
}
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);

View File

@@ -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);
}