Skip to content

Commit bf493a3

Browse files
committed
Merge branch 'nest'
2 parents 2307cc7 + 67f9524 commit bf493a3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/builder/BooleanSpec.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public BooleanSpec not(Function<PredicateSpec, BooleanSpec> fn) {
115115
return fn.apply(new NotOpSpec(this.routeBuilder, this.builder, this.operator));
116116
}
117117

118+
public BooleanSpec nested(Function<PredicateSpec, BooleanSpec> fn) {
119+
return fn.apply(new NestedOpSpec(this.routeBuilder, this.builder, this.operator));
120+
}
121+
118122
}
119123

120124
public static class NotOpSpec extends BooleanOpSpec {
@@ -131,4 +135,17 @@ public BooleanSpec asyncPredicate(AsyncPredicate<ServerWebExchange> predicate) {
131135

132136
}
133137

138+
public static class NestedOpSpec extends BooleanOpSpec {
139+
140+
NestedOpSpec(Route.AsyncBuilder routeBuilder, RouteLocatorBuilder.Builder builder, Operator operator) {
141+
super(routeBuilder, builder, operator);
142+
}
143+
144+
@Override
145+
public BooleanSpec asyncPredicate(AsyncPredicate<ServerWebExchange> predicate) {
146+
return super.asyncPredicate(predicate);
147+
}
148+
149+
}
150+
134151
}

spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ public void andNotWorksWithParameter() {
9494
.isEqualTo("hasquery");
9595
}
9696

97+
@Test
98+
public void andNestedOrQuery1() {
99+
testClient.get().uri("/andnestedquery?query1=hasquery1").exchange().expectBody(String.class)
100+
.isEqualTo("hasquery1,notsupplied");
101+
}
102+
103+
@Test
104+
public void andNestedOrQuery2() {
105+
testClient.get().uri("/andnestedquery?query2=hasquery2").exchange().expectBody(String.class)
106+
.isEqualTo("notsupplied,hasquery2");
107+
}
108+
97109
@EnableAutoConfiguration
98110
@SpringBootConfiguration
99111
@Import(DefaultTestConfig.class)
@@ -108,6 +120,12 @@ String andnotquery(@RequestParam(name = "myquery", defaultValue = "notsupplied")
108120
return myquery;
109121
}
110122

123+
@GetMapping("/httpbin/andnestedquery")
124+
String andnotquery(@RequestParam(name = "query1", defaultValue = "notsupplied") String query1,
125+
@RequestParam(name = "query2", defaultValue = "notsupplied") String query2) {
126+
return query1 + "," + query2;
127+
}
128+
111129
@GetMapping("/httpbin/hasquery")
112130
String hasquery() {
113131
return "hasquery";
@@ -128,6 +146,8 @@ RouteLocator testRouteLocator(RouteLocatorBuilder builder) {
128146
.query("myquery")
129147
.filters(f -> f.setPath("/httpbin/hasquery"))
130148
.uri(uri))
149+
.route("and_nested_query1_or_query2", r -> r.path("/andnestedquery").and().nested(p -> p.query("query1").or().query("query2"))
150+
.filters(f -> f.prefixPath("/httpbin")).uri(uri))
131151
.build();
132152
}
133153

0 commit comments

Comments
 (0)