From 51ff3685d6d742a71c22169d69d80038dfbb5f28 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Tue, 27 Jul 2021 22:31:17 -0400 Subject: [PATCH] Changes default of StripPrefix filter from 0 to 1. Fixes gh-2033 --- .../filter/factory/StripPrefixGatewayFilterFactory.java | 2 +- .../StripPrefixGatewayFilterFactoryIntegrationTests.java | 7 ++++++- .../src/test/resources/application.yml | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactory.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactory.java index 22874f94..541568ae 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactory.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactory.java @@ -96,7 +96,7 @@ public class StripPrefixGatewayFilterFactory public static class Config { - private int parts; + private int parts = 1; public int getParts() { return parts; diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java index dc9bb966..7f5458fc 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java @@ -38,10 +38,15 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen public class StripPrefixGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { @Test - public void stripPrefixFilterDefaultValuesWork() { + public void stripPrefixFilterStripMultiplePartsValuesWork() { testClient.get().uri("/foo/bar/get").header("Host", "www.stripprefix.org").exchange().expectStatus().isOk(); } + @Test + public void stripPrefixFilterDefaultPartsWork() { + testClient.get().uri("/foo/get").header("Host", "www.stripprefixdefault.org").exchange().expectStatus().isOk(); + } + @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) diff --git a/spring-cloud-gateway-server/src/test/resources/application.yml b/spring-cloud-gateway-server/src/test/resources/application.yml index 64af423a..7574e248 100644 --- a/spring-cloud-gateway-server/src/test/resources/application.yml +++ b/spring-cloud-gateway-server/src/test/resources/application.yml @@ -429,6 +429,15 @@ spring: filters: - StripPrefix=2 + # ===================================== + - id: strip_prefix_default_test + uri: ${test.uri} + predicates: + - Host=**.stripprefixdefault.org + - Path=/foo/** + filters: + - StripPrefix + # ===================================== - id: rewrite_path_test uri: ${test.uri}