Move to predicate package. Create Method Predicate.
This commit is contained in:
@@ -8,11 +8,12 @@ import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter;
|
||||
import org.springframework.cloud.gateway.handler.GatewayFilteringWebHandler;
|
||||
import org.springframework.cloud.gateway.handler.HostPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.GatewayPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.predicate.HostPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.predicate.GatewayPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.GatewayWebHandler;
|
||||
import org.springframework.cloud.gateway.handler.ServerWebExchangePredicateHandlerMapping;
|
||||
import org.springframework.cloud.gateway.handler.UrlPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.predicate.MethodPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.predicate.UrlPredicateFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
@@ -70,6 +71,11 @@ public class GatewayAutoConfiguration {
|
||||
return new UrlPredicateFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MethodPredicateFactory methodPredicateFactory() {
|
||||
return new MethodPredicateFactory();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
protected static class GatewayActuatorConfiguration {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.function.Predicate;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties.Route;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.handler.predicate.GatewayPredicateFactory;
|
||||
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cloud.gateway.handler;
|
||||
package org.springframework.cloud.gateway.handler.predicate;
|
||||
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cloud.gateway.handler;
|
||||
package org.springframework.cloud.gateway.handler.predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.cloud.gateway.handler.predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class MethodPredicateFactory implements GatewayPredicateFactory {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Method";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ServerWebExchange> create(String method) {
|
||||
//TODO: caching can happen here
|
||||
return exchange -> {
|
||||
HttpMethod requestMethod = exchange.getRequest().getMethod();
|
||||
return requestMethod.matches(method);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cloud.gateway.handler;
|
||||
package org.springframework.cloud.gateway.handler.predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -8,12 +8,9 @@ import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties.Route;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.handler.HostPredicateFactory;
|
||||
import org.springframework.cloud.gateway.handler.ServerWebExchangePredicateHandlerMapping;
|
||||
import org.springframework.cloud.gateway.handler.UrlPredicateFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
@@ -17,7 +17,9 @@ spring:
|
||||
- name: Host
|
||||
value: '**.foo.org'
|
||||
- name: Url
|
||||
value: '/headers'
|
||||
value: /headers
|
||||
- name: Method
|
||||
value: GET
|
||||
|
||||
# =====================================
|
||||
- id: default_path_to_httpbin
|
||||
|
||||
Reference in New Issue
Block a user