From 3d2be39670a6f8bbc81684fd26acf736aa4a10ef Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 3 Mar 2020 14:03:04 -0500 Subject: [PATCH 1/7] Adds support for spring.codec.* in modify request body filter. Also adds test for support added in modify response. Fixes gh-1596 --- .../config/GatewayAutoConfiguration.java | 9 ++--- ...ModifyRequestBodyGatewayFilterFactory.java | 8 ++++- ...odifyResponseBodyGatewayFilterFactory.java | 33 +++++++---------- ...yRequestBodyGatewayFilterFactoryTests.java | 23 +++++++++++- ...ResponseBodyGatewayFilterFactoryTests.java | 35 ++++++++++++++++++- ...onseBodyGatewayFilterFactoryUnitTests.java | 3 +- 6 files changed, 83 insertions(+), 28 deletions(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index e0bda2e8..5ba878ee 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -434,8 +434,9 @@ public class GatewayAutoConfiguration { } @Bean - public ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory() { - return new ModifyRequestBodyGatewayFilterFactory(); + public ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory( + ServerCodecConfigurer codecConfigurer) { + return new ModifyRequestBodyGatewayFilterFactory(codecConfigurer.getReaders()); } @Bean @@ -447,8 +448,8 @@ public class GatewayAutoConfiguration { public ModifyResponseBodyGatewayFilterFactory modifyResponseBodyGatewayFilterFactory( ServerCodecConfigurer codecConfigurer, Set bodyDecoders, Set bodyEncoders) { - return new ModifyResponseBodyGatewayFilterFactory(codecConfigurer, bodyDecoders, - bodyEncoders); + return new ModifyResponseBodyGatewayFilterFactory(codecConfigurer.getReaders(), + bodyDecoders, bodyEncoders); } @Bean diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java index 128887b3..3c4b2dfc 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactory.java @@ -53,9 +53,15 @@ public class ModifyRequestBodyGatewayFilterFactory extends this.messageReaders = HandlerStrategies.withDefaults().messageReaders(); } + public ModifyRequestBodyGatewayFilterFactory( + List> messageReaders) { + super(Config.class); + this.messageReaders = messageReaders; + } + @Deprecated public ModifyRequestBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) { - this(); + this(codecConfigurer.getReaders()); } @Override diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java index 3352e234..2830c0e1 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactory.java @@ -41,6 +41,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.http.client.reactive.ClientHttpResponse; +import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; @@ -49,6 +50,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.server.HandlerStrategies; import org.springframework.web.server.ServerWebExchange; import static java.util.function.Function.identity; @@ -61,17 +63,16 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O public class ModifyResponseBodyGatewayFilterFactory extends AbstractGatewayFilterFactory { - @Nullable - private final ServerCodecConfigurer codecConfigurer; - private final Map messageBodyDecoders; private final Map messageBodyEncoders; + private final List> messageReaders; + @Deprecated public ModifyResponseBodyGatewayFilterFactory() { super(Config.class); - this.codecConfigurer = null; + messageReaders = HandlerStrategies.withDefaults().messageReaders(); messageBodyDecoders = Collections.emptyMap(); messageBodyEncoders = Collections.emptyMap(); } @@ -79,16 +80,17 @@ public class ModifyResponseBodyGatewayFilterFactory extends @Deprecated public ModifyResponseBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer) { super(Config.class); - this.codecConfigurer = codecConfigurer; + this.messageReaders = codecConfigurer.getReaders(); messageBodyDecoders = Collections.emptyMap(); messageBodyEncoders = Collections.emptyMap(); } - public ModifyResponseBodyGatewayFilterFactory(ServerCodecConfigurer codecConfigurer, + public ModifyResponseBodyGatewayFilterFactory( + List> messageReaders, Set messageBodyDecoders, Set messageBodyEncoders) { super(Config.class); - this.codecConfigurer = codecConfigurer; + this.messageReaders = messageReaders; this.messageBodyDecoders = messageBodyDecoders.stream() .collect(Collectors.toMap(MessageBodyDecoder::encodingType, identity())); this.messageBodyEncoders = messageBodyEncoders.stream() @@ -98,7 +100,7 @@ public class ModifyResponseBodyGatewayFilterFactory extends @Override public GatewayFilter apply(Config config) { ModifyResponseGatewayFilter gatewayFilter = new ModifyResponseGatewayFilter( - config, codecConfigurer); + config); gatewayFilter.setFactory(this); return gatewayFilter; } @@ -185,20 +187,16 @@ public class ModifyResponseBodyGatewayFilterFactory extends private final Config config; - @Nullable - private final ServerCodecConfigurer codecConfigurer; - private GatewayFilterFactory gatewayFilterFactory; - @Deprecated public ModifyResponseGatewayFilter(Config config) { this(config, null); } + @Deprecated public ModifyResponseGatewayFilter(Config config, @Nullable ServerCodecConfigurer codecConfigurer) { this.config = config; - this.codecConfigurer = codecConfigurer; } @Override @@ -299,13 +297,8 @@ public class ModifyResponseBodyGatewayFilterFactory extends private ClientResponse prepareClientResponse(Publisher body, HttpHeaders httpHeaders) { ClientResponse.Builder builder; - if (codecConfigurer != null) { - builder = ClientResponse.create(exchange.getResponse().getStatusCode(), - codecConfigurer.getReaders()); - } - else { - builder = ClientResponse.create(exchange.getResponse().getStatusCode()); - } + builder = ClientResponse.create(exchange.getResponse().getStatusCode(), + messageReaders); return builder.headers(headers -> headers.putAll(httpHeaders)) .body(Flux.from(body)).build(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java index 230dc692..3010e5dc 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java @@ -42,7 +42,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Junghoon Song */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) +@SpringBootTest(webEnvironment = RANDOM_PORT, + properties = "spring.codec.max-in-memory-size=13") @DirtiesContext public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTests { @@ -66,6 +67,17 @@ public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTes .isEqualTo("modifyrequest"); } + @Test + public void modifyRequestBodyToLarge() { + testClient.post().uri("/post") + .header("Host", "www.modifyrequestbodyemptytolarge.org") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) + .body(BodyInserters.fromValue("request")).exchange().expectStatus() + .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody() + .jsonPath("message") + .isEqualTo("Exceeded limit on max bytes to buffer : 13"); + } + @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) @@ -95,6 +107,15 @@ public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTes return Mono.just(body.toUpperCase()); })) .uri(uri)) + .route("test_modify_request_body_to_large", r -> r.order(-1) + .host("**.modifyrequestbodyemptytolarge.org") + .filters(f -> f.modifyRequestBody(String.class, String.class, + MediaType.APPLICATION_JSON_VALUE, + (serverWebExchange, body) -> { + return Mono.just( + "tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge-tolarge"); + })) + .uri(uri)) .build(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index dc668c67..5c1d351f 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -33,18 +33,32 @@ import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.util.UriComponentsBuilder; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) +@SpringBootTest(webEnvironment = RANDOM_PORT, + properties = "spring.codec.max-in-memory-size=40") @DirtiesContext public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTests { + private static final String toLarge; + + static { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 1000; i++) { + sb.append("to-large-"); + } + toLarge = sb.toString(); + } + @Test public void testModificationOfResponseBody() { URI uri = UriComponentsBuilder.fromUriString(this.baseUri + "/").build(true) @@ -55,6 +69,17 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe .json("{\"value\": \"httpbin compatible home\", \"length\": 23}"); } + @Test + public void modifyResponeBodyToLarge() { + testClient.post().uri("/post") + .header("Host", "www.modifyresponsebodyjavatoolarge.org") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .body(BodyInserters.fromValue(toLarge)).exchange().expectStatus() + .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody() + .jsonPath("message") + .isEqualTo("Exceeded limit on max bytes to buffer : 40"); + } + @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) @@ -77,6 +102,14 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe return Mono.just(modifiedResponse); })) .uri(uri)) + .route("modify_response_java_test_to_large", + r -> r.path("/").and().host("www.modifyresponsebodyjavatoolarge.org") + .filters(f -> f.prefixPath("/httpbin").modifyResponseBody( + String.class, String.class, + (webExchange, originalResponse) -> { + return Mono.just(toLarge); + })) + .uri(uri)) .build(); } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryUnitTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryUnitTests.java index 2ccfbe7b..4f191602 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryUnitTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryUnitTests.java @@ -34,7 +34,8 @@ public class ModifyResponseBodyGatewayFilterFactoryUnitTests { config.setOutClass(Integer.class); config.setNewContentType("mycontenttype"); GatewayFilter filter = new ModifyResponseBodyGatewayFilterFactory( - new DefaultServerCodecConfigurer(), emptySet(), emptySet()).apply(config); + new DefaultServerCodecConfigurer().getReaders(), emptySet(), emptySet()) + .apply(config); assertThat(filter.toString()).contains("String").contains("Integer") .contains("mycontenttype"); } From a5e3cb7eb96fdea7444fa89a12614677e2158e1b Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 4 Mar 2020 16:45:55 +0000 Subject: [PATCH 2/7] Update SNAPSHOT to 2.2.2.RELEASE --- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 5 +++++ pom.xml | 10 +++++----- spring-cloud-gateway-core/pom.xml | 2 +- .../ModifyResponseBodyGatewayFilterFactoryTests.java | 4 ++-- spring-cloud-gateway-dependencies/pom.xml | 4 ++-- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 9ab2dd65..bfa45962 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE spring-cloud-gateway-docs pom diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 0c8ee8cc..67528dc3 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -10,6 +10,7 @@ |spring.cloud.gateway.discovery.locator.route-id-prefix | | The prefix for the routeId, defaults to discoveryClient.getClass().getSimpleName() + "_". Service Id will be appended to create the routeId. |spring.cloud.gateway.discovery.locator.url-expression | 'lb://'+serviceId | SpEL expression that create the uri for each route, defaults to: 'lb://'+serviceId. |spring.cloud.gateway.enabled | true | Enables gateway functionality. +|spring.cloud.gateway.fail-on-route-definition-error | true | Option to fail on route definition errors, defaults to true. Otherwise, a warning is logged. |spring.cloud.gateway.filter.remove-hop-by-hop.headers | | |spring.cloud.gateway.filter.remove-hop-by-hop.order | | |spring.cloud.gateway.filter.request-rate-limiter.deny-empty-key | true | Switch to deny requests if the Key Resolver returns an empty key, defaults to true. @@ -27,6 +28,8 @@ |spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping | false | If global CORS config should be added to the URL handler. |spring.cloud.gateway.globalcors.cors-configurations | | |spring.cloud.gateway.httpclient.connect-timeout | | The connect timeout in millis, the default is 45s. +|spring.cloud.gateway.httpclient.max-header-size | | The max response header size. +|spring.cloud.gateway.httpclient.max-initial-line-length | | The max initial line length. |spring.cloud.gateway.httpclient.pool.acquire-timeout | | Only for type FIXED, the maximum time in millis to wait for aquiring. |spring.cloud.gateway.httpclient.pool.max-connections | | Only for type FIXED, the maximum number of connections before starting pending acquisition on existing ones. |spring.cloud.gateway.httpclient.pool.max-idle-time | | Time in millis after which the channel will be closed. If NULL, there is no max idle time. @@ -54,6 +57,7 @@ |spring.cloud.gateway.httpclient.ssl.trusted-x509-certificates | | Trusted certificates for verifying the remote endpoint's certificate. |spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager | false | Installs the netty InsecureTrustManagerFactory. This is insecure and not suitable for production. |spring.cloud.gateway.httpclient.websocket.max-frame-payload-length | | Max frame payload length. +|spring.cloud.gateway.httpclient.websocket.proxy-ping | true | Proxy ping frames to downstream services, defaults to true. |spring.cloud.gateway.httpclient.wiretap | false | Enables wiretap debugging for Netty HttpClient. |spring.cloud.gateway.httpserver.wiretap | false | Enables wiretap debugging for Netty HttpServer. |spring.cloud.gateway.loadbalancer.use404 | false | @@ -64,6 +68,7 @@ |spring.cloud.gateway.redis-rate-limiter.include-headers | true | Whether or not to include headers containing rate limiter information, defaults to true. |spring.cloud.gateway.redis-rate-limiter.remaining-header | X-RateLimit-Remaining | The name of the header that returns number of remaining requests during the current second. |spring.cloud.gateway.redis-rate-limiter.replenish-rate-header | X-RateLimit-Replenish-Rate | The name of the header that returns the replenish rate configuration. +|spring.cloud.gateway.redis-rate-limiter.requested-tokens-header | X-RateLimit-Requested-Tokens | The name of the header that returns the requested tokens configuration. |spring.cloud.gateway.routes | | List of Routes. |spring.cloud.gateway.set-status.original-status-header-name | | The name of the header which contains http code of the proxied request. |spring.cloud.gateway.streaming-media-types | | diff --git a/pom.xml b/pom.xml index e5389081..fc03a794 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE pom Spring Cloud Gateway @@ -15,7 +15,7 @@ org.springframework.cloud spring-cloud-build - 2.2.3.BUILD-SNAPSHOT + 2.2.3.RELEASE @@ -52,9 +52,9 @@ UTF-8 UTF-8 1.8 - 2.2.2.BUILD-SNAPSHOT - 2.2.2.BUILD-SNAPSHOT - 1.0.1.BUILD-SNAPSHOT + 2.2.2.RELEASE + 2.2.2.RELEASE + 1.0.2.RELEASE 0.6 1.0.1.RELEASE diff --git a/spring-cloud-gateway-core/pom.xml b/spring-cloud-gateway-core/pom.xml index f166e3e0..87c0b873 100644 --- a/spring-cloud-gateway-core/pom.xml +++ b/spring-cloud-gateway-core/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE .. spring-cloud-gateway-core diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index 5c1d351f..f6e3e164 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -102,8 +102,8 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe return Mono.just(modifiedResponse); })) .uri(uri)) - .route("modify_response_java_test_to_large", - r -> r.path("/").and().host("www.modifyresponsebodyjavatoolarge.org") + .route("modify_response_java_test_to_large", r -> r.path("/").and() + .host("www.modifyresponsebodyjavatoolarge.org") .filters(f -> f.prefixPath("/httpbin").modifyResponseBody( String.class, String.class, (webExchange, originalResponse) -> { diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index 394c7088..03d3d2a1 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,12 +6,12 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.2.3.BUILD-SNAPSHOT + 2.2.3.RELEASE spring-cloud-gateway-dependencies - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index fc9c1fb6..212ee179 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index bc70f1ee..a5d4d028 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE .. diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index a38005e3..f264eef2 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index 9278fc0d..b2e53158 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.2.RELEASE .. spring-cloud-starter-gateway From 4404a22ca736042fc8a51371e43f7b6b241ff5a4 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 4 Mar 2020 16:47:25 +0000 Subject: [PATCH 3/7] Going back to snapshots --- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 5 ----- pom.xml | 10 +++++----- spring-cloud-gateway-core/pom.xml | 2 +- .../ModifyResponseBodyGatewayFilterFactoryTests.java | 4 ++-- spring-cloud-gateway-dependencies/pom.xml | 4 ++-- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 10 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index bfa45962..9ab2dd65 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT spring-cloud-gateway-docs pom diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 67528dc3..0c8ee8cc 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -10,7 +10,6 @@ |spring.cloud.gateway.discovery.locator.route-id-prefix | | The prefix for the routeId, defaults to discoveryClient.getClass().getSimpleName() + "_". Service Id will be appended to create the routeId. |spring.cloud.gateway.discovery.locator.url-expression | 'lb://'+serviceId | SpEL expression that create the uri for each route, defaults to: 'lb://'+serviceId. |spring.cloud.gateway.enabled | true | Enables gateway functionality. -|spring.cloud.gateway.fail-on-route-definition-error | true | Option to fail on route definition errors, defaults to true. Otherwise, a warning is logged. |spring.cloud.gateway.filter.remove-hop-by-hop.headers | | |spring.cloud.gateway.filter.remove-hop-by-hop.order | | |spring.cloud.gateway.filter.request-rate-limiter.deny-empty-key | true | Switch to deny requests if the Key Resolver returns an empty key, defaults to true. @@ -28,8 +27,6 @@ |spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping | false | If global CORS config should be added to the URL handler. |spring.cloud.gateway.globalcors.cors-configurations | | |spring.cloud.gateway.httpclient.connect-timeout | | The connect timeout in millis, the default is 45s. -|spring.cloud.gateway.httpclient.max-header-size | | The max response header size. -|spring.cloud.gateway.httpclient.max-initial-line-length | | The max initial line length. |spring.cloud.gateway.httpclient.pool.acquire-timeout | | Only for type FIXED, the maximum time in millis to wait for aquiring. |spring.cloud.gateway.httpclient.pool.max-connections | | Only for type FIXED, the maximum number of connections before starting pending acquisition on existing ones. |spring.cloud.gateway.httpclient.pool.max-idle-time | | Time in millis after which the channel will be closed. If NULL, there is no max idle time. @@ -57,7 +54,6 @@ |spring.cloud.gateway.httpclient.ssl.trusted-x509-certificates | | Trusted certificates for verifying the remote endpoint's certificate. |spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager | false | Installs the netty InsecureTrustManagerFactory. This is insecure and not suitable for production. |spring.cloud.gateway.httpclient.websocket.max-frame-payload-length | | Max frame payload length. -|spring.cloud.gateway.httpclient.websocket.proxy-ping | true | Proxy ping frames to downstream services, defaults to true. |spring.cloud.gateway.httpclient.wiretap | false | Enables wiretap debugging for Netty HttpClient. |spring.cloud.gateway.httpserver.wiretap | false | Enables wiretap debugging for Netty HttpServer. |spring.cloud.gateway.loadbalancer.use404 | false | @@ -68,7 +64,6 @@ |spring.cloud.gateway.redis-rate-limiter.include-headers | true | Whether or not to include headers containing rate limiter information, defaults to true. |spring.cloud.gateway.redis-rate-limiter.remaining-header | X-RateLimit-Remaining | The name of the header that returns number of remaining requests during the current second. |spring.cloud.gateway.redis-rate-limiter.replenish-rate-header | X-RateLimit-Replenish-Rate | The name of the header that returns the replenish rate configuration. -|spring.cloud.gateway.redis-rate-limiter.requested-tokens-header | X-RateLimit-Requested-Tokens | The name of the header that returns the requested tokens configuration. |spring.cloud.gateway.routes | | List of Routes. |spring.cloud.gateway.set-status.original-status-header-name | | The name of the header which contains http code of the proxied request. |spring.cloud.gateway.streaming-media-types | | diff --git a/pom.xml b/pom.xml index fc03a794..e5389081 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT pom Spring Cloud Gateway @@ -15,7 +15,7 @@ org.springframework.cloud spring-cloud-build - 2.2.3.RELEASE + 2.2.3.BUILD-SNAPSHOT @@ -52,9 +52,9 @@ UTF-8 UTF-8 1.8 - 2.2.2.RELEASE - 2.2.2.RELEASE - 1.0.2.RELEASE + 2.2.2.BUILD-SNAPSHOT + 2.2.2.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT 0.6 1.0.1.RELEASE diff --git a/spring-cloud-gateway-core/pom.xml b/spring-cloud-gateway-core/pom.xml index 87c0b873..f166e3e0 100644 --- a/spring-cloud-gateway-core/pom.xml +++ b/spring-cloud-gateway-core/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT .. spring-cloud-gateway-core diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index f6e3e164..5c1d351f 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -102,8 +102,8 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe return Mono.just(modifiedResponse); })) .uri(uri)) - .route("modify_response_java_test_to_large", r -> r.path("/").and() - .host("www.modifyresponsebodyjavatoolarge.org") + .route("modify_response_java_test_to_large", + r -> r.path("/").and().host("www.modifyresponsebodyjavatoolarge.org") .filters(f -> f.prefixPath("/httpbin").modifyResponseBody( String.class, String.class, (webExchange, originalResponse) -> { diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index 03d3d2a1..394c7088 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,12 +6,12 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.2.3.RELEASE + 2.2.3.BUILD-SNAPSHOT spring-cloud-gateway-dependencies - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index 212ee179..fc9c1fb6 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index a5d4d028..bc70f1ee 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index f264eef2..a38005e3 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index b2e53158..9278fc0d 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.RELEASE + 2.2.2.BUILD-SNAPSHOT .. spring-cloud-starter-gateway From 97a87144ff5496115c49dedf4475b193d46209e1 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 4 Mar 2020 16:47:25 +0000 Subject: [PATCH 4/7] Bumping versions to 2.2.3.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 10 +++++----- spring-cloud-gateway-core/pom.xml | 2 +- spring-cloud-gateway-dependencies/pom.xml | 4 ++-- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 9ab2dd65..1429fa12 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT spring-cloud-gateway-docs pom diff --git a/pom.xml b/pom.xml index e5389081..a08d132a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT pom Spring Cloud Gateway @@ -15,7 +15,7 @@ org.springframework.cloud spring-cloud-build - 2.2.3.BUILD-SNAPSHOT + 2.2.3.RELEASE @@ -52,9 +52,9 @@ UTF-8 UTF-8 1.8 - 2.2.2.BUILD-SNAPSHOT - 2.2.2.BUILD-SNAPSHOT - 1.0.1.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT + 1.0.3.BUILD-SNAPSHOT 0.6 1.0.1.RELEASE diff --git a/spring-cloud-gateway-core/pom.xml b/spring-cloud-gateway-core/pom.xml index f166e3e0..3a780b56 100644 --- a/spring-cloud-gateway-core/pom.xml +++ b/spring-cloud-gateway-core/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT .. spring-cloud-gateway-core diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index 394c7088..4470278c 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,12 +6,12 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.2.3.BUILD-SNAPSHOT + 2.2.4.BUILD-SNAPSHOT spring-cloud-gateway-dependencies - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index fc9c1fb6..d980011f 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index bc70f1ee..df828a87 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index a38005e3..0929246b 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index 9278fc0d..69c6835f 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 2.2.2.BUILD-SNAPSHOT + 2.2.3.BUILD-SNAPSHOT .. spring-cloud-starter-gateway From 5f48b1d253e13535fcae80b66f0ae5e58a6eb6cb Mon Sep 17 00:00:00 2001 From: Tobias Gies Date: Wed, 4 Mar 2020 20:10:24 +0100 Subject: [PATCH 5/7] Falls back to unresolved hostname in ForwardedHeadersFilter to prevent NPE. fixes gh-1601 --- .../headers/ForwardedHeadersFilter.java | 5 +++- .../headers/ForwardedHeadersFilterTests.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java index 9cf096b3..8a39b428 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java @@ -116,7 +116,10 @@ public class ForwardedHeadersFilter implements HttpHeadersFilter, Ordered { InetSocketAddress remoteAddress = request.getRemoteAddress(); if (remoteAddress != null) { - String forValue = remoteAddress.getAddress().getHostAddress(); + // If remoteAddress is unresolved, calling getHostAddress() would cause a + // NullPointerException. + String forValue = remoteAddress.isUnresolved() ? remoteAddress.getHostName() + : remoteAddress.getAddress().getHostAddress(); int port = remoteAddress.getPort(); if (port >= 0) { forValue = forValue + ":" + port; diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java index 0de5b9d8..11c37082 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java @@ -131,6 +131,30 @@ public class ForwardedHeadersFilterTests { .containsEntry("for", "\"10.0.0.1:80\""); } + @Test + public void unresolvedRemoteAddressFallsBackToHostName() throws UnknownHostException { + MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get") + .remoteAddress( + InetSocketAddress.createUnresolved("unresolvable-hostname", 80)) + .build(); + + ForwardedHeadersFilter filter = new ForwardedHeadersFilter(); + + HttpHeaders headers = filter.filter(request.getHeaders(), + MockServerWebExchange.from(request)); + + assertThat(headers.get(FORWARDED_HEADER)).hasSize(1); + + List forwardeds = ForwardedHeadersFilter + .parse(headers.get(FORWARDED_HEADER)); + + assertThat(forwardeds).hasSize(1); + Forwarded forwarded = forwardeds.get(0); + + assertThat(forwarded.getValues()).containsEntry("proto", "http") + .containsEntry("for", "\"unresolvable-hostname:80\""); + } + @Test public void forwardedParsedCorrectly() { String[] valid = new String[] { "for=\"_gazonk\"", From 5d8ef981f3a1f6bbd4e4994826f6bf174df4b8d3 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 4 Mar 2020 15:35:32 -0500 Subject: [PATCH 6/7] Removes duplicate entry --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index a08d132a..6b6e07ee 100644 --- a/pom.xml +++ b/pom.xml @@ -140,11 +140,6 @@ blockhound-junit-platform ${blockhound.version} - - io.projectreactor.tools - blockhound-junit-platform - ${blockhound.version} - From 98287d530a8dd48690af67f86ed37e3d1020f3dc Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 4 Mar 2020 15:36:19 -0500 Subject: [PATCH 7/7] Formatting --- .../rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index 5c1d351f..f6e3e164 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -102,8 +102,8 @@ public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTe return Mono.just(modifiedResponse); })) .uri(uri)) - .route("modify_response_java_test_to_large", - r -> r.path("/").and().host("www.modifyresponsebodyjavatoolarge.org") + .route("modify_response_java_test_to_large", r -> r.path("/").and() + .host("www.modifyresponsebodyjavatoolarge.org") .filters(f -> f.prefixPath("/httpbin").modifyResponseBody( String.class, String.class, (webExchange, originalResponse) -> {