Skip to content

Commit b30188e

Browse files
committed
Adds back removed methods and fields as deprecated.
See gh-3313
1 parent b435ce3 commit b30188e

File tree

9 files changed

+93
-25
lines changed

9 files changed

+93
-25
lines changed

spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/ProxyExchange.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import jakarta.servlet.http.HttpServletResponse;
4646
import jakarta.servlet.http.HttpServletResponseWrapper;
4747

48+
import org.springframework.cloud.gateway.mvc.config.ProxyProperties;
4849
import org.springframework.core.Conventions;
4950
import org.springframework.core.MethodParameter;
5051
import org.springframework.core.ParameterizedTypeReference;
@@ -137,6 +138,12 @@
137138
*/
138139
public class ProxyExchange<T> {
139140

141+
/**
142+
* Contains headers that are considered case-sensitive by default.
143+
* @deprecated {@link ProxyProperties#DEFAULT_SENSITIVE}
144+
*/
145+
public static Set<String> DEFAULT_SENSITIVE = ProxyProperties.DEFAULT_SENSITIVE;
146+
140147
private URI uri;
141148

142149
private RestTemplate rest;
@@ -203,6 +210,17 @@ public ProxyExchange<T> headers(HttpHeaders headers) {
203210
return this;
204211
}
205212

213+
/**
214+
* Sets the names of sensitive headers that are not passed downstream to the backend
215+
* service.
216+
* @param names the names of sensitive headers
217+
* @return this for convenience
218+
* @deprecated {@link #excluded(String...)}
219+
*/
220+
public ProxyExchange<T> sensitive(String... names) {
221+
return excluded(names);
222+
}
223+
206224
/**
207225
* Sets the names of excluded headers that are not passed downstream to the backend
208226
* service.

spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/config/ProxyExchangeArgumentResolver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void setAutoForwardedHeaders(Set<String> autoForwardedHeaders) {
6262
: autoForwardedHeaders.stream().map(String::toLowerCase).collect(toSet());
6363
}
6464

65+
@Deprecated
66+
public void setSensitive(Set<String> excluded) {
67+
setExcluded(excluded);
68+
}
69+
6570
public void setExcluded(Set<String> excluded) {
6671
this.excluded = excluded;
6772
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
@ConfigurationProperties("spring.cloud.gateway.proxy")
3838
public class ProxyProperties {
3939

40+
/**
41+
* Contains headers that are considered case-sensitive by default.
42+
*/
43+
public static Set<String> DEFAULT_SENSITIVE = Set.of("cookie", "authorization");
44+
45+
/**
46+
* Contains headers that are skipped by default.
47+
*/
48+
public static Set<String> DEFAULT_SKIPPED = Set.of("content-length", "host");
49+
4050
/**
4151
* Fixed header values that will be added to all downstream requests.
4252
*/
@@ -50,12 +60,13 @@ public class ProxyProperties {
5060
/**
5161
* A set of sensitive header names that will not be sent downstream by default.
5262
*/
53-
private Set<String> sensitive = Set.of("cookie", "authorization");
63+
private Set<String> sensitive = DEFAULT_SENSITIVE;
5464

5565
/**
56-
* A set of header names that will not be sent downstream because they could be problematic.
66+
* A set of header names that will not be sent downstream because they could be
67+
* problematic.
5768
*/
58-
private Set<String> skipped = Set.of("content-length", "host");
69+
private Set<String> skipped = DEFAULT_SKIPPED;
5970

6071
public Map<String, String> getHeaders() {
6172
return headers;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public void post() {
115115
@Test
116116
public void postJsonWithWhitespace() {
117117
var json = """
118-
{
119-
"foo": "bar"
120-
}""";
118+
{
119+
"foo": "bar"
120+
}""";
121121

122122
var headers = new HttpHeaders();
123123
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -456,8 +456,7 @@ public ResponseEntity<Map<String, List<String>>> defaultSensitiveHeaders(
456456
}
457457

458458
@PostMapping("/proxy/checkContentLength")
459-
public ResponseEntity<?> checkContentLength(
460-
ProxyExchange<byte[]> proxy) {
459+
public ResponseEntity<?> checkContentLength(ProxyExchange<byte[]> proxy) {
461460
return proxy.uri(home.toString() + "/checkContentLength").post();
462461
}
463462

@@ -506,8 +505,9 @@ public List<Bar> bars(@RequestBody List<Foo> foos, @RequestHeader HttpHeaders he
506505
}
507506

508507
@PostMapping("/checkContentLength")
509-
public ResponseEntity<?> checkContentLength(@RequestHeader(name = "Content-Length", required = false) Integer contentLength,
510-
@RequestBody String json) {
508+
public ResponseEntity<?> checkContentLength(
509+
@RequestHeader(name = "Content-Length", required = false) Integer contentLength,
510+
@RequestBody String json) {
511511
if (contentLength != null && contentLength != json.length()) {
512512
return ResponseEntity.badRequest().build();
513513
}

spring-cloud-gateway-mvc/src/test/java/org/springframework/cloud/gateway/mvc/http/GetWithBodyRequestClientHttpRequestFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,18 @@ public void destroy() throws Exception {
113113
}
114114
}
115115

116+
/**
117+
* Represents an HTTP GET request with a body.
118+
*/
116119
public static class GetWithEntity extends HttpEntityEnclosingRequestBase {
117120

118-
public static final String METHOD_NAME = "GET";
119-
120121
public GetWithEntity(final URI uri) {
121122
setURI(uri);
122123
}
123124

124125
@Override
125126
public String getMethod() {
126-
return METHOD_NAME;
127+
return HttpMethod.GET.name();
127128
}
128129

129130
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.reactivestreams.Publisher;
3030
import reactor.core.publisher.Mono;
3131

32+
import org.springframework.cloud.gateway.webflux.config.ProxyProperties;
3233
import org.springframework.core.ParameterizedTypeReference;
3334
import org.springframework.core.io.buffer.DataBuffer;
3435
import org.springframework.http.HttpHeaders;
@@ -111,6 +112,12 @@
111112
*/
112113
public class ProxyExchange<T> {
113114

115+
/**
116+
* Contains headers that are considered case-sensitive by default.
117+
* @deprecated {@link ProxyProperties#DEFAULT_SENSITIVE}
118+
*/
119+
public static Set<String> DEFAULT_SENSITIVE = ProxyProperties.DEFAULT_SENSITIVE;
120+
114121
private HttpMethod httpMethod;
115122

116123
private URI uri;
@@ -190,6 +197,17 @@ public ProxyExchange<T> headers(HttpHeaders headers) {
190197
return this;
191198
}
192199

200+
/**
201+
* Sets the names of sensitive headers that are not passed downstream to the backend
202+
* service.
203+
* @param names the names of sensitive headers
204+
* @return this for convenience
205+
* @deprecated {@link #excluded(String...)}
206+
*/
207+
public ProxyExchange<T> sensitive(String... names) {
208+
return excluded(names);
209+
}
210+
193211
/**
194212
* Sets the names of excluded headers that are not passed downstream to the backend
195213
* service.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public void setAutoForwardedHeaders(Set<String> autoForwardedHeaders) {
5858
this.autoForwardedHeaders = autoForwardedHeaders;
5959
}
6060

61+
@Deprecated
62+
public void setSensitive(Set<String> excluded) {
63+
setExcluded(excluded);
64+
}
65+
6166
public void setExcluded(Set<String> excluded) {
6267
this.excluded = excluded;
6368
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
@ConfigurationProperties("spring.cloud.gateway.proxy")
3838
public class ProxyProperties {
3939

40+
/**
41+
* Contains headers that are considered case-sensitive by default.
42+
*/
43+
public static Set<String> DEFAULT_SENSITIVE = Set.of("cookie", "authorization");
44+
45+
/**
46+
* Contains headers that are skipped by default.
47+
*/
48+
public static Set<String> DEFAULT_SKIPPED = Set.of("content-length", "host");
49+
4050
/**
4151
* Fixed header values that will be added to all downstream requests.
4252
*/
@@ -50,12 +60,13 @@ public class ProxyProperties {
5060
/**
5161
* A set of sensitive header names that will not be sent downstream by default.
5262
*/
53-
private Set<String> sensitive = Set.of("cookie", "authorization");
63+
private Set<String> sensitive = DEFAULT_SENSITIVE;
5464

5565
/**
56-
* A set of header names that will not be sent downstream because they could be problematic.
66+
* A set of header names that will not be sent downstream because they could be
67+
* problematic.
5768
*/
58-
private Set<String> skipped = Set.of("content-length", "host");
69+
private Set<String> skipped = DEFAULT_SKIPPED;
5970

6071
public Map<String, String> getHeaders() {
6172
return headers;

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858

5959
import static org.assertj.core.api.Assertions.assertThat;
6060

61-
@SpringBootTest(properties = { "spring.cloud.gateway.proxy.skipped=host" },
62-
webEnvironment = WebEnvironment.RANDOM_PORT)
61+
@SpringBootTest(properties = { "spring.cloud.gateway.proxy.skipped=host" }, webEnvironment = WebEnvironment.RANDOM_PORT)
6362
@ContextConfiguration(classes = TestApplication.class)
6463
@DirtiesContext
6564
public class ProductionConfigurationTests {
@@ -122,9 +121,9 @@ public void post() throws Exception {
122121
@Test
123122
public void postJsonWithWhitespace() {
124123
var json = """
125-
{
126-
"foo": "bar"
127-
}""";
124+
{
125+
"foo": "bar"
126+
}""";
128127

129128
var headers = new HttpHeaders();
130129
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -369,8 +368,7 @@ public Mono<ResponseEntity<Map<String, List<String>>>> defaultSensitiveHeaders(
369368
}
370369

371370
@PostMapping("/proxy/checkContentLength")
372-
public Mono<ResponseEntity<byte[]>> checkContentLength(
373-
ProxyExchange<byte[]> proxy) {
371+
public Mono<ResponseEntity<byte[]>> checkContentLength(ProxyExchange<byte[]> proxy) {
374372
return proxy.uri(home.toString() + "/checkContentLength").post();
375373
}
376374

@@ -430,8 +428,9 @@ public List<Bar> bars(@RequestBody List<Foo> foos, @RequestHeader HttpHeaders he
430428
}
431429

432430
@PostMapping("/checkContentLength")
433-
public ResponseEntity<?> checkContentLength(@RequestHeader(name = "Content-Length", required = false) Integer contentLength,
434-
@RequestBody String json) {
431+
public ResponseEntity<?> checkContentLength(
432+
@RequestHeader(name = "Content-Length", required = false) Integer contentLength,
433+
@RequestBody String json) {
435434
if (contentLength != null && contentLength != json.length()) {
436435
return ResponseEntity.badRequest().build();
437436
}

0 commit comments

Comments
 (0)