From 041a8dc08f4f80f8ff66c42ea765a7f9037efc19 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 19 Mar 2020 12:04:39 -0400 Subject: [PATCH 1/5] Bumps build to 2.3.0.BUILD-SNAPSHOT --- pom.xml | 2 +- spring-cloud-gateway-dependencies/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 42ff7bc7..53cbeb55 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.springframework.cloud spring-cloud-build - 2.2.4.BUILD-SNAPSHOT + 2.3.0.BUILD-SNAPSHOT diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index 4470278c..fe5bb95c 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,7 +6,7 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.2.4.BUILD-SNAPSHOT + 2.3.0.BUILD-SNAPSHOT From 5718f85a15234d5838751bcd910e465e4ff1f51e Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 1 Apr 2020 14:53:30 -0400 Subject: [PATCH 2/5] Fixes rough ordering of routes by id alphabetically. --- .../src/test/resources/application.yml | 264 +++++++++--------- 1 file changed, 134 insertions(+), 130 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/resources/application.yml b/spring-cloud-gateway-core/src/test/resources/application.yml index 4f016bf6..e82c6d44 100644 --- a/spring-cloud-gateway-core/src/test/resources/application.yml +++ b/spring-cloud-gateway-core/src/test/resources/application.yml @@ -68,6 +68,45 @@ spring: filters: - AddResponseHeader=X-Request-Foo, Bar + # ===================================== + - id: circuitbreaker_exception_fallback_test + uri: ${test.uri} + predicates: + - Host=**.circuitbreakerexceptionfallback.org + filters: + - name: CircuitBreaker + args: + name: fallbackcmd + fallbackUri: forward:/circuitbreakerExceptionFallback + + # ===================================== + - id: circuitbreaker_fallback_test + uri: ${test.uri} + predicates: + - Host=**.circuitbreakerfallback.org + filters: + - name: CircuitBreaker + args: + name: fallbackcmd + fallbackUri: forward:/circuitbreakerFallbackController + + # ===================================== + - id: change_uri_test + uri: ${test.uri} + predicates: + - Host=**.changeuri.org + - Header=X-CF-Forwarded-Url + filters: + - RequestHeaderToRequestUri=X-CF-Forwarded-Url + + # ===================================== + - id: cloudfoundry_routeservice_test + uri: ${test.uri} + predicates: + - CloudFoundryRouteService= + filters: + - RequestHeaderToRequestUri=X-CF-Forwarded-Url + # ===================================== - id: dedupe_response_header_test uri: ${test.uri} @@ -89,32 +128,18 @@ spring: - DedupeResponseHeader=Scout-Cookie, RETAIN_LAST - DedupeResponseHeader=Next-Week-Lottery-Numbers, RETAIN_UNIQUE - # ===================================== - - id: rewrite_response_header_test - uri: ${test.uri} - predicates: - - Host=**.rewriteresponseheader.org - - Path=/headers - filters: - - AddResponseHeader=X-Request-Foo, /42?user=ford&password=omg!what&flag=true - - RewriteResponseHeader=X-Request-Foo, password=[^&]+, password=*** - - # ===================================== - - id: rewrite_location_response_header_test - uri: ${test.uri} - predicates: - - Host=**.rewritelocationresponseheader.org - - Path=/headers - filters: - - AddResponseHeader=Location, https://backend.org:443/v1/some/object/id - - RewriteLocationResponseHeader - # ===================================== - id: forward_test uri: forward:/localcontroller predicates: - Host=**.forward.org + # ===================================== + - id: header_test + uri: ${test.uri} + predicates: + - Header=Foo, .* + # ===================================== - id: host_backwards_compatible_test uri: ${test.uri} @@ -173,52 +198,6 @@ spring: filters: - Hystrix=successcmd - # ===================================== - - id: sccb_success_test - uri: ${test.uri} - predicates: - - Host=**.sccbsuccess.org - filters: - - CircuitBreaker=successcmd - - # ===================================== - - id: sccb_timeout_test - uri: ${test.uri} - predicates: - - Host=**.sccbtimeout.org - filters: - - CircuitBreaker=timeoutcmd - - # ===================================== - - id: sccb_failure_test - uri: ${test.uri} - predicates: - - Host=**.sccbfailure.org - filters: - - CircuitBreaker=failcmd - - # ===================================== - - id: circuitbreaker_exception_fallback_test - uri: ${test.uri} - predicates: - - Host=**.circuitbreakerexceptionfallback.org - filters: - - name: CircuitBreaker - args: - name: fallbackcmd - fallbackUri: forward:/circuitbreakerExceptionFallback - - # ===================================== - - id: circuitbreaker_fallback_test - uri: ${test.uri} - predicates: - - Host=**.circuitbreakerfallback.org - filters: - - name: CircuitBreaker - args: - name: fallbackcmd - fallbackUri: forward:/circuitbreakerFallbackController - # ===================================== - id: load_balancer_client_test uri: lb://testservice @@ -272,6 +251,28 @@ spring: filters: - SetPath=/anything/multi{num} + # ===================================== + - id: per_route_connect_timeout + uri: http://localhost:32167 + predicates: + - name: Path + args: + pattern: /connect/delay/{timeout} + metadata: + connect-timeout: 5 + + # ===================================== + - id: per_route_response_timeout + uri: ${test.uri} + predicates: + - name: Path + args: + pattern: /route/delay/{timeout} + filters: + - StripPrefix=1 + metadata: + response-timeout: 1000 + # ===================================== - id: redirect_to_test uri: ${test.uri} @@ -299,6 +300,50 @@ spring: - AddResponseHeader=X-Request-Foo, Bar - RemoveResponseHeader=X-Request-Foo + # ===================================== + - id: rewrite_location_response_header_test + uri: ${test.uri} + predicates: + - Host=**.rewritelocationresponseheader.org + - Path=/headers + filters: + - AddResponseHeader=Location, https://backend.org:443/v1/some/object/id + - RewriteLocationResponseHeader + + # ===================================== + - id: rewrite_response_header_test + uri: ${test.uri} + predicates: + - Host=**.rewriteresponseheader.org + - Path=/headers + filters: + - AddResponseHeader=X-Request-Foo, /42?user=ford&password=omg!what&flag=true + - RewriteResponseHeader=X-Request-Foo, password=[^&]+, password=*** + + # ===================================== + - id: sccb_failure_test + uri: ${test.uri} + predicates: + - Host=**.sccbfailure.org + filters: + - CircuitBreaker=failcmd + + # ===================================== + - id: sccb_success_test + uri: ${test.uri} + predicates: + - Host=**.sccbsuccess.org + filters: + - CircuitBreaker=successcmd + + # ===================================== + - id: sccb_timeout_test + uri: ${test.uri} + predicates: + - Host=**.sccbtimeout.org + filters: + - CircuitBreaker=timeoutcmd + # ===================================== - id: secure_headers_test uri: ${test.uri} @@ -325,15 +370,6 @@ spring: filters: - SetPath=/{subdomain} - # ===================================== - - id: strip_prefix_test - uri: ${test.uri} - predicates: - - Host=**.stripprefix.org - - Path=/foo/** - filters: - - StripPrefix=2 - # ===================================== - id: set_response_header_test uri: ${test.uri} @@ -365,6 +401,15 @@ spring: filters: - SetStatus=BAD_REQUEST + # ===================================== + - id: strip_prefix_test + uri: ${test.uri} + predicates: + - Host=**.stripprefix.org + - Path=/foo/** + filters: + - StripPrefix=2 + # ===================================== - id: rewrite_path_test uri: ${test.uri} @@ -377,45 +422,7 @@ spring: - AddRequestHeader=X-Request-Foo, Bar - AddRequestHeader=X-Request-Baz, Bat - # ===================================== - - id: weight_high_test - uri: ${test.uri} - predicates: - - Host=**.weighthigh.org - - Weight=group1, 8 - - # ===================================== - - id: header_test - uri: ${test.uri} - predicates: - - Header=Foo, .* - - # ===================================== - - id: change_uri_test - uri: ${test.uri} - predicates: - - Host=**.changeuri.org - - Header=X-CF-Forwarded-Url - filters: - - RequestHeaderToRequestUri=X-CF-Forwarded-Url - - # ===================================== - - id: cloudfoundry_routeservice_test - uri: ${test.uri} - predicates: - - CloudFoundryRouteService= - filters: - - RequestHeaderToRequestUri=X-CF-Forwarded-Url - - # ===================================== - - id: default_path_to_httpbin - uri: ${test.uri} - order: 10000 - predicates: - - name: Path - args: - pattern: /** - # ===================================== + # ===================================== - id: route_with_metadata uri: ${test.uri} order: 10000 @@ -426,28 +433,25 @@ spring: metadata: optionName: "OptionValue" compositeObject: - name: "value" + name: "value" iAmNumber: 1 + # ===================================== - - id: per_route_response_timeout + - id: weight_high_test uri: ${test.uri} predicates: - - name: Path - args: - pattern: /route/delay/{timeout} - filters: - - StripPrefix=1 - metadata: - response-timeout: 1000 + - Host=**.weighthigh.org + - Weight=group1, 8 + # ===================================== - - id: per_route_connect_timeout - uri: http://localhost:32167 + # should be last and not follow alphabetical order + - id: default_path_to_httpbin + uri: ${test.uri} + order: 10000 predicates: - - name: Path - args: - pattern: /connect/delay/{timeout} - metadata: - connect-timeout: 5 + - name: Path + args: + pattern: /** hystrix.command.successcmd.execution.isolation.thread.timeoutInMilliseconds: 5000 From 429a44f94296459d5f5b7d7c085eaa063e7b41ca Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 1 Apr 2020 15:14:55 -0400 Subject: [PATCH 3/5] Adds CookieRoutePredicateFactoryIntegrationTests --- ...RoutePredicateFactoryIntegrationTests.java | 67 +++++++++++++++++++ .../src/test/resources/application.yml | 7 ++ 2 files changed, 74 insertions(+) create mode 100644 spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java new file mode 100644 index 00000000..fb5cc054 --- /dev/null +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.gateway.handler.predicate; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.test.BaseWebClientTests; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpHeaders; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT) +public class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { + + @Test + public void cookieRegexWorks() { + assertCookieValue("helloaaaaa"); + + assertCookieValue("hello"); + } + + private void assertCookieValue(String value) { + testClient.get().uri("/cookie").header(HttpHeaders.HOST, "www.cookieregex.org") + .cookie("mycookie", value) + .exchange().expectStatus().isOk() + .expectHeader() + .valueEquals(ROUTE_ID_HEADER, "cookie_regex_test") + .expectBody(String.class).isEqualTo(value); + } + + @EnableAutoConfiguration + @SpringBootConfiguration + @Import(DefaultTestConfig.class) + @RestController + public static class TestConfig { + + @GetMapping("/httpbin/cookie") + public String cookie(@CookieValue("mycookie") String mycookie) { + return mycookie; + } + + } +} diff --git a/spring-cloud-gateway-core/src/test/resources/application.yml b/spring-cloud-gateway-core/src/test/resources/application.yml index e82c6d44..97310680 100644 --- a/spring-cloud-gateway-core/src/test/resources/application.yml +++ b/spring-cloud-gateway-core/src/test/resources/application.yml @@ -107,6 +107,13 @@ spring: filters: - RequestHeaderToRequestUri=X-CF-Forwarded-Url + # ===================================== + - id: cookie_regex_test + uri: ${test.uri} + predicates: + - Host=**.cookieregex.org + - Cookie=mycookie, hello.* + # ===================================== - id: dedupe_response_header_test uri: ${test.uri} From 73b01f81e60e8d41d22f7fb26d48d94cf7db1174 Mon Sep 17 00:00:00 2001 From: ukayani Date: Tue, 7 Apr 2020 23:52:03 -0400 Subject: [PATCH 4/5] Preserves the order of route definitions. This preserves the order in which route definitions are composited together and likewise for routes this would ensure that route definitions from properties do not lose their relative ordering. Fixes gh-1660 --- .../cloud/gateway/route/CompositeRouteDefinitionLocator.java | 3 ++- .../cloud/gateway/route/CompositeRouteLocator.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java index 4cafd929..18d929b0 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteDefinitionLocator.java @@ -49,7 +49,8 @@ public class CompositeRouteDefinitionLocator implements RouteDefinitionLocator { @Override public Flux getRouteDefinitions() { - return this.delegates.flatMap(RouteDefinitionLocator::getRouteDefinitions) + return this.delegates + .flatMapSequential(RouteDefinitionLocator::getRouteDefinitions) .flatMap(routeDefinition -> { if (routeDefinition.getId() == null) { return randomId().map(id -> { diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java index 13e1f7ce..a58dce30 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CompositeRouteLocator.java @@ -31,7 +31,7 @@ public class CompositeRouteLocator implements RouteLocator { @Override public Flux getRoutes() { - return this.delegates.flatMap(RouteLocator::getRoutes); + return this.delegates.flatMapSequential(RouteLocator::getRoutes); } } From cf13c284e1e1462eb5c86ade2bb31d8df321f8f9 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 8 Apr 2020 11:47:43 -0400 Subject: [PATCH 5/5] formatting --- .../CookieRoutePredicateFactoryIntegrationTests.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java index fb5cc054..3f1d6476 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java @@ -45,9 +45,7 @@ public class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTe private void assertCookieValue(String value) { testClient.get().uri("/cookie").header(HttpHeaders.HOST, "www.cookieregex.org") - .cookie("mycookie", value) - .exchange().expectStatus().isOk() - .expectHeader() + .cookie("mycookie", value).exchange().expectStatus().isOk().expectHeader() .valueEquals(ROUTE_ID_HEADER, "cookie_regex_test") .expectBody(String.class).isEqualTo(value); } @@ -64,4 +62,5 @@ public class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTe } } + }