Skip to content

Commit ebef287

Browse files
committed
Migrates proxy-exchange-webflux properties to new namespace
from spring.cloud.gateway.proxy to spring.cloud.gateway.proxy-exchange.webflux Fixes gh-3362
1 parent eca63cb commit ebef287

File tree

7 files changed

+206
-10
lines changed

7 files changed

+206
-10
lines changed

spring-cloud-gateway-webflux/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<artifactId>spring-boot-starter-actuator</artifactId>
3131
<scope>test</scope>
3232
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-properties-migrator</artifactId>
36+
<scope>test</scope>
37+
</dependency>
3338
<dependency>
3439
<groupId>org.springframework.boot</groupId>
3540
<artifactId>spring-boot-configuration-processor</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.gateway.webflux.config;
18+
19+
import java.util.HashSet;
20+
import java.util.LinkedHashMap;
21+
import java.util.Map;
22+
import java.util.Set;
23+
24+
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.cloud.gateway.webflux.ProxyExchange;
26+
import org.springframework.http.HttpHeaders;
27+
28+
/**
29+
* Configuration properties for the {@link ProxyExchange} argument handler in
30+
* <code>@RequestMapping</code> methods.
31+
*
32+
* @author Dave Syer
33+
* @author Tim Ysewyn
34+
* @author Joris Kuipers
35+
* @author Spencer Gibb
36+
*
37+
*/
38+
@ConfigurationProperties(ProxyExchangeWebfluxProperties.PREFIX)
39+
public class ProxyExchangeWebfluxProperties {
40+
41+
/**
42+
* Properties prefix.
43+
*/
44+
public static final String PREFIX = "spring.cloud.gateway.proxy-exchange.webflux";
45+
46+
/**
47+
* Contains headers that are considered case-sensitive by default.
48+
*/
49+
public static Set<String> DEFAULT_SENSITIVE = Set.of("cookie", "authorization");
50+
51+
/**
52+
* Contains headers that are skipped by default.
53+
*/
54+
public static Set<String> DEFAULT_SKIPPED = Set.of("content-length", "host");
55+
56+
/**
57+
* Fixed header values that will be added to all downstream requests.
58+
*/
59+
private Map<String, String> headers = new LinkedHashMap<>();
60+
61+
/**
62+
* A set of header names that should be sent downstream by default.
63+
*/
64+
private Set<String> autoForward = new HashSet<>();
65+
66+
/**
67+
* A set of sensitive header names that will not be sent downstream by default.
68+
*/
69+
private Set<String> sensitive = DEFAULT_SENSITIVE;
70+
71+
/**
72+
* A set of header names that will not be sent downstream because they could be
73+
* problematic.
74+
*/
75+
private Set<String> skipped = DEFAULT_SKIPPED;
76+
77+
public Map<String, String> getHeaders() {
78+
return headers;
79+
}
80+
81+
public void setHeaders(Map<String, String> headers) {
82+
this.headers = headers;
83+
}
84+
85+
public Set<String> getAutoForward() {
86+
return autoForward;
87+
}
88+
89+
public void setAutoForward(Set<String> autoForward) {
90+
this.autoForward = autoForward;
91+
}
92+
93+
public Set<String> getSensitive() {
94+
return sensitive;
95+
}
96+
97+
public void setSensitive(Set<String> sensitive) {
98+
this.sensitive = sensitive;
99+
}
100+
101+
public Set<String> getSkipped() {
102+
return skipped;
103+
}
104+
105+
public void setSkipped(Set<String> skipped) {
106+
this.skipped = skipped;
107+
}
108+
109+
public HttpHeaders convertHeaders() {
110+
HttpHeaders headers = new HttpHeaders();
111+
for (String key : this.headers.keySet()) {
112+
headers.set(key, this.headers.get(key));
113+
}
114+
return headers;
115+
}
116+
117+
}

spring-cloud-gateway-webflux/src/main/java/org/springframework/cloud/gateway/webflux/config/ProxyProperties.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Set;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
2526
import org.springframework.cloud.gateway.webflux.ProxyExchange;
2627
import org.springframework.http.HttpHeaders;
2728

@@ -32,8 +33,10 @@
3233
* @author Dave Syer
3334
* @author Tim Ysewyn
3435
* @author Joris Kuipers
36+
* @deprecated {@link ProxyExchangeWebfluxProperties}
3537
*
3638
*/
39+
@Deprecated
3740
@ConfigurationProperties("spring.cloud.gateway.proxy")
3841
public class ProxyProperties {
3942

@@ -53,7 +56,7 @@ public class ProxyProperties {
5356
private Map<String, String> headers = new LinkedHashMap<>();
5457

5558
/**
56-
* A set of header names that should be send downstream by default.
59+
* A set of header names that should be sent downstream by default.
5760
*/
5861
private Set<String> autoForward = new HashSet<>();
5962

@@ -68,6 +71,7 @@ public class ProxyProperties {
6871
*/
6972
private Set<String> skipped = DEFAULT_SKIPPED;
7073

74+
@DeprecatedConfigurationProperty(replacement = ProxyExchangeWebfluxProperties.PREFIX + ".headers", since = "4.3.0")
7175
public Map<String, String> getHeaders() {
7276
return headers;
7377
}
@@ -76,6 +80,8 @@ public void setHeaders(Map<String, String> headers) {
7680
this.headers = headers;
7781
}
7882

83+
@DeprecatedConfigurationProperty(replacement = ProxyExchangeWebfluxProperties.PREFIX + ".auto-forward",
84+
since = "4.3.0")
7985
public Set<String> getAutoForward() {
8086
return autoForward;
8187
}
@@ -84,6 +90,8 @@ public void setAutoForward(Set<String> autoForward) {
8490
this.autoForward = autoForward;
8591
}
8692

93+
@DeprecatedConfigurationProperty(replacement = ProxyExchangeWebfluxProperties.PREFIX + ".sensitive",
94+
since = "4.3.0")
8795
public Set<String> getSensitive() {
8896
return sensitive;
8997
}
@@ -92,6 +100,7 @@ public void setSensitive(Set<String> sensitive) {
92100
this.sensitive = sensitive;
93101
}
94102

103+
@DeprecatedConfigurationProperty(replacement = ProxyExchangeWebfluxProperties.PREFIX + ".skipped", since = "4.3.0")
95104
public Set<String> getSkipped() {
96105
return skipped;
97106
}

spring-cloud-gateway-webflux/src/main/java/org/springframework/cloud/gateway/webflux/config/ProxyResponseAutoConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
@Configuration(proxyBeanMethods = false)
4949
@ConditionalOnWebApplication
5050
@ConditionalOnClass({ HandlerMethodReturnValueHandler.class, WebClient.class })
51-
@EnableConfigurationProperties(ProxyProperties.class)
51+
@EnableConfigurationProperties({ ProxyExchangeWebfluxProperties.class, ProxyProperties.class })
5252
public class ProxyResponseAutoConfiguration implements WebFluxConfigurer {
5353

5454
@Autowired
@@ -57,18 +57,18 @@ public class ProxyResponseAutoConfiguration implements WebFluxConfigurer {
5757
@Bean
5858
@ConditionalOnMissingBean
5959
public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver(Optional<WebClient.Builder> optional,
60-
ProxyProperties proxy) {
60+
ProxyExchangeWebfluxProperties properties) {
6161
WebClient.Builder builder = optional.orElse(WebClient.builder());
6262
WebClient template = builder.build();
6363
ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(template);
64-
resolver.setHeaders(proxy.convertHeaders());
65-
resolver.setAutoForwardedHeaders(proxy.getAutoForward());
64+
resolver.setHeaders(properties.convertHeaders());
65+
resolver.setAutoForwardedHeaders(properties.getAutoForward());
6666
Set<String> excludedHeaderNames = new HashSet<>();
67-
if (proxy.getSensitive() != null) {
68-
excludedHeaderNames.addAll(proxy.getSensitive());
67+
if (properties.getSensitive() != null) {
68+
excludedHeaderNames.addAll(properties.getSensitive());
6969
}
70-
if (proxy.getSkipped() != null) {
71-
excludedHeaderNames.addAll(proxy.getSkipped());
70+
if (properties.getSkipped() != null) {
71+
excludedHeaderNames.addAll(properties.getSkipped());
7272
}
7373
resolver.setExcluded(excludedHeaderNames);
7474
return resolver;

spring-cloud-gateway-webflux/src/test/java/org/springframework/cloud/gateway/webflux/ProductionConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262

6363
import static org.assertj.core.api.Assertions.assertThat;
6464

65-
@SpringBootTest(properties = { "spring.cloud.gateway.proxy.skipped=host" }, webEnvironment = WebEnvironment.RANDOM_PORT)
65+
@SpringBootTest(properties = { "spring.cloud.gateway.proxy-exchange.webflux.skipped=host" },
66+
webEnvironment = WebEnvironment.RANDOM_PORT)
6667
@ContextConfiguration(classes = TestApplication.class)
6768
@DirtiesContext
6869
@ExtendWith(OutputCaptureExtension.class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.gateway.webflux.config;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.SpringBootConfiguration;
23+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
26+
import org.springframework.test.context.ActiveProfiles;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
@SuppressWarnings("unchecked")
31+
@SpringBootTest(properties = {}, webEnvironment = WebEnvironment.RANDOM_PORT)
32+
@ActiveProfiles("propertiesmigrationtests")
33+
public class ProxyExchangeWebfluxPropertiesMigrationTests {
34+
35+
@Autowired
36+
ProxyProperties properties;
37+
38+
@Test
39+
public void deprecatedRoutePropertiesWork() {
40+
assertThat(properties.getHeaders()).hasSize(2);
41+
assertThat(properties.getAutoForward()).hasSize(2);
42+
assertThat(properties.getSensitive()).hasSize(2);
43+
assertThat(properties.getSkipped()).hasSize(3);
44+
}
45+
46+
@SpringBootConfiguration
47+
@EnableAutoConfiguration
48+
protected static class TestConfiguration {
49+
50+
}
51+
52+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
spring.cloud.gateway.proxy:
2+
headers:
3+
X-Foo: xfooval
4+
X-Bar: xbarval
5+
auto-forward:
6+
- X-FWD1
7+
- X-FWD2
8+
sensitive: X-S1, X-S21
9+
skipped: X-SK1, X-SK2, X-SK3
10+
logging:
11+
level:
12+
org.springframework.cloud.gateway.server.mvc: TRACE

0 commit comments

Comments
 (0)