Skip to content

Commit a830c8e

Browse files
committed
Merge branch '4.1.x' into 4.2.x
2 parents 5e4aff5 + 88fce67 commit a830c8e

File tree

7 files changed

+61
-26
lines changed

7 files changed

+61
-26
lines changed

docs/modules/ROOT/partials/_configprops.adoc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
|spring.cloud.gateway.default-filters | | List of filter definitions that are applied to every route.
55
|spring.cloud.gateway.discovery.locator.enabled | `+++false+++` | Flag that enables DiscoveryClient gateway integration.
6-
|spring.cloud.gateway.discovery.locator.filters | |
6+
|spring.cloud.gateway.discovery.locator.filters | |
77
|spring.cloud.gateway.discovery.locator.include-expression | `+++true+++` | SpEL expression that will evaluate whether to include a service in gateway integration or not, defaults to: true.
88
|spring.cloud.gateway.discovery.locator.lower-case-service-id | `+++false+++` | Option to lower case serviceId in predicates and filters, defaults to false. Useful with eureka when it automatically uppercases serviceId. so MYSERIVCE, would match /myservice/**
9-
|spring.cloud.gateway.discovery.locator.predicates | |
9+
|spring.cloud.gateway.discovery.locator.predicates | |
1010
|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.
1111
|spring.cloud.gateway.discovery.locator.url-expression | `+++'lb://'+serviceId+++` | SpEL expression that create the uri for each route, defaults to: 'lb://'+serviceId.
1212
|spring.cloud.gateway.enabled | `+++true+++` | Enables gateway functionality.
@@ -20,7 +20,7 @@
2020
|spring.cloud.gateway.filter.hystrix.enabled | `+++true+++` | Enables the hystrix filter.
2121
|spring.cloud.gateway.filter.json-to-grpc.enabled | `+++true+++` | Enables the JSON to gRPC filter.
2222
|spring.cloud.gateway.filter.local-response-cache.enabled | `+++false+++` | Enables the local-response-cache filter.
23-
|spring.cloud.gateway.filter.local-response-cache.request.no-cache-strategy | `+++skip-update-cache-entry+++` |
23+
|spring.cloud.gateway.filter.local-response-cache.request.no-cache-strategy | `+++skip-update-cache-entry+++` |
2424
|spring.cloud.gateway.filter.local-response-cache.size | | Maximum size of the cache to evict entries for this route (in KB, MB and GB).
2525
|spring.cloud.gateway.filter.local-response-cache.time-to-live | `+++5m+++` | Time to expire a cache entry (expressed in s for seconds, m for minutes, and h for hours).
2626
|spring.cloud.gateway.filter.map-request-header.enabled | `+++true+++` | Enables the map-request-header filter.
@@ -29,15 +29,15 @@
2929
|spring.cloud.gateway.filter.prefix-path.enabled | `+++true+++` | Enables the prefix-path filter.
3030
|spring.cloud.gateway.filter.preserve-host-header.enabled | `+++true+++` | Enables the preserve-host-header filter.
3131
|spring.cloud.gateway.filter.redirect-to.enabled | `+++true+++` | Enables the redirect-to filter.
32-
|spring.cloud.gateway.filter.remove-hop-by-hop.headers | |
33-
|spring.cloud.gateway.filter.remove-hop-by-hop.order | `+++0+++` |
32+
|spring.cloud.gateway.filter.remove-hop-by-hop.headers | |
33+
|spring.cloud.gateway.filter.remove-hop-by-hop.order | `+++0+++` |
3434
|spring.cloud.gateway.filter.remove-request-header.enabled | `+++true+++` | Enables the remove-request-header filter.
3535
|spring.cloud.gateway.filter.remove-request-parameter.enabled | `+++true+++` | Enables the remove-request-parameter filter.
3636
|spring.cloud.gateway.filter.remove-response-header.enabled | `+++true+++` | Enables the remove-response-header filter.
3737
|spring.cloud.gateway.filter.request-header-size.enabled | `+++true+++` | Enables the request-header-size filter.
3838
|spring.cloud.gateway.filter.request-header-to-request-uri.enabled | `+++true+++` | Enables the request-header-to-request-uri filter.
39-
|spring.cloud.gateway.filter.request-rate-limiter.default-key-resolver | |
40-
|spring.cloud.gateway.filter.request-rate-limiter.default-rate-limiter | |
39+
|spring.cloud.gateway.filter.request-rate-limiter.default-key-resolver | |
40+
|spring.cloud.gateway.filter.request-rate-limiter.default-rate-limiter | |
4141
|spring.cloud.gateway.filter.request-rate-limiter.enabled | `+++true+++` | Enables the request-rate-limiter filter.
4242
|spring.cloud.gateway.filter.request-size.enabled | `+++true+++` | Enables the request-size filter.
4343
|spring.cloud.gateway.filter.retry.enabled | `+++true+++` | Enables the retry filter.
@@ -47,16 +47,16 @@
4747
|spring.cloud.gateway.filter.rewrite-request-parameter.enabled | `+++true+++` | Enables the rewrite-request-parameter filter.
4848
|spring.cloud.gateway.filter.rewrite-response-header.enabled | `+++true+++` | Enables the rewrite-response-header filter.
4949
|spring.cloud.gateway.filter.save-session.enabled | `+++true+++` | Enables the save-session filter.
50-
|spring.cloud.gateway.filter.secure-headers.content-security-policy | `+++default-src 'self' https:; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'; script-src https:; style-src 'self' https: 'unsafe-inline'+++` |
51-
|spring.cloud.gateway.filter.secure-headers.content-type-options | `+++nosniff+++` |
52-
|spring.cloud.gateway.filter.secure-headers.disable | |
53-
|spring.cloud.gateway.filter.secure-headers.download-options | `+++noopen+++` |
50+
|spring.cloud.gateway.filter.secure-headers.content-security-policy | `+++default-src 'self' https:; font-src 'self' https: data:; img-src 'self' https: data:; object-src 'none'; script-src https:; style-src 'self' https: 'unsafe-inline'+++` |
51+
|spring.cloud.gateway.filter.secure-headers.content-type-options | `+++nosniff+++` |
52+
|spring.cloud.gateway.filter.secure-headers.disable | |
53+
|spring.cloud.gateway.filter.secure-headers.download-options | `+++noopen+++` |
5454
|spring.cloud.gateway.filter.secure-headers.enabled | `+++true+++` | Enables the secure-headers filter.
55-
|spring.cloud.gateway.filter.secure-headers.frame-options | `+++DENY+++` |
56-
|spring.cloud.gateway.filter.secure-headers.permitted-cross-domain-policies | `+++none+++` |
57-
|spring.cloud.gateway.filter.secure-headers.referrer-policy | `+++no-referrer+++` |
58-
|spring.cloud.gateway.filter.secure-headers.strict-transport-security | `+++max-age=631138519+++` |
59-
|spring.cloud.gateway.filter.secure-headers.xss-protection-header | `+++1 ; mode=block+++` |
55+
|spring.cloud.gateway.filter.secure-headers.frame-options | `+++DENY+++` |
56+
|spring.cloud.gateway.filter.secure-headers.permitted-cross-domain-policies | `+++none+++` |
57+
|spring.cloud.gateway.filter.secure-headers.referrer-policy | `+++no-referrer+++` |
58+
|spring.cloud.gateway.filter.secure-headers.strict-transport-security | `+++max-age=631138519+++` |
59+
|spring.cloud.gateway.filter.secure-headers.xss-protection-header | `+++1 ; mode=block+++` |
6060
|spring.cloud.gateway.filter.set-path.enabled | `+++true+++` | Enables the set-path filter.
6161
|spring.cloud.gateway.filter.set-request-header.enabled | `+++true+++` | Enables the set-request-header filter.
6262
|spring.cloud.gateway.filter.set-request-host-header.enabled | `+++true+++` | Enables the set-request-host-header filter.
@@ -76,7 +76,7 @@
7676
|spring.cloud.gateway.global-filter.route-to-request-url.enabled | `+++true+++` | Enables the route-to-request-url global filter.
7777
|spring.cloud.gateway.global-filter.websocket-routing.enabled | `+++true+++` | Enables the websocket-routing global filter.
7878
|spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping | `+++false+++` | If global CORS config should be added to the URL handler.
79-
|spring.cloud.gateway.globalcors.cors-configurations | |
79+
|spring.cloud.gateway.globalcors.cors-configurations | |
8080
|spring.cloud.gateway.handler-mapping.order | `+++1+++` | The order of RoutePredicateHandlerMapping.
8181
|spring.cloud.gateway.httpclient.compression | `+++false+++` | Enables compression for Netty HttpClient.
8282
|spring.cloud.gateway.httpclient.connect-timeout | | The connect timeout in millis, the default is 30s.
@@ -113,7 +113,7 @@
113113
|spring.cloud.gateway.httpclient.websocket.proxy-ping | `+++true+++` | Proxy ping frames to downstream services, defaults to true.
114114
|spring.cloud.gateway.httpclient.wiretap | `+++false+++` | Enables wiretap debugging for Netty HttpClient.
115115
|spring.cloud.gateway.httpserver.wiretap | `+++false+++` | Enables wiretap debugging for Netty HttpServer.
116-
|spring.cloud.gateway.loadbalancer.use404 | `+++false+++` |
116+
|spring.cloud.gateway.loadbalancer.use404 | `+++false+++` |
117117
|spring.cloud.gateway.metrics.enabled | `+++false+++` | Enables the collection of metrics data.
118118
|spring.cloud.gateway.metrics.prefix | `+++spring.cloud.gateway+++` | The prefix of all metrics emitted by gateway.
119119
|spring.cloud.gateway.metrics.tags | | Tags map that added to metrics.
@@ -161,7 +161,7 @@
161161
|spring.cloud.gateway.predicate.weight.enabled | `+++true+++` | Enables the weight predicate.
162162
|spring.cloud.gateway.predicate.xforwarded-remote-addr.enabled | `+++true+++` | Enables the xforwarded-remote-addr predicate.
163163
|spring.cloud.gateway.redis-rate-limiter.burst-capacity-header | `+++X-RateLimit-Burst-Capacity+++` | The name of the header that returns the burst capacity configuration.
164-
|spring.cloud.gateway.redis-rate-limiter.config | |
164+
|spring.cloud.gateway.redis-rate-limiter.config | |
165165
|spring.cloud.gateway.redis-rate-limiter.include-headers | `+++true+++` | Whether or not to include headers containing rate limiter information, defaults to true.
166166
|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.
167167
|spring.cloud.gateway.redis-rate-limiter.replenish-rate-header | `+++X-RateLimit-Replenish-Rate+++` | The name of the header that returns the replenish rate configuration.
@@ -172,7 +172,7 @@
172172
|spring.cloud.gateway.route-refresh-listener.enabled | `+++true+++` | If RouteRefreshListener should be turned on.
173173
|spring.cloud.gateway.routes | | List of Routes.
174174
|spring.cloud.gateway.set-status.original-status-header-name | | The name of the header which contains http code of the proxied request.
175-
|spring.cloud.gateway.streaming-media-types | |
175+
|spring.cloud.gateway.streaming-media-types | |
176176
|spring.cloud.gateway.x-forwarded.enabled | `+++true+++` | If the XForwardedHeadersFilter is enabled.
177177
|spring.cloud.gateway.x-forwarded.for-append | `+++true+++` | If appending X-Forwarded-For as a list is enabled.
178178
|spring.cloud.gateway.x-forwarded.for-enabled | `+++true+++` | If X-Forwarded-For is enabled.
@@ -186,4 +186,4 @@
186186
|spring.cloud.gateway.x-forwarded.proto-append | `+++true+++` | If appending X-Forwarded-Proto as a list is enabled.
187187
|spring.cloud.gateway.x-forwarded.proto-enabled | `+++true+++` | If X-Forwarded-Proto is enabled.
188188
189-
|===
189+
|===

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/AbstractGatewayFilterFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.gateway.filter.factory;
1818

19+
import org.springframework.cloud.gateway.event.EnableBodyCachingEvent;
1920
import org.springframework.cloud.gateway.support.AbstractConfigurable;
2021
import org.springframework.context.ApplicationEventPublisher;
2122
import org.springframework.context.ApplicationEventPublisherAware;
@@ -43,6 +44,13 @@ protected ApplicationEventPublisher getPublisher() {
4344
return this.publisher;
4445
}
4546

47+
protected void enableBodyCaching(String routeId) {
48+
if (routeId != null && getPublisher() != null) {
49+
// send an event to enable caching
50+
getPublisher().publishEvent(new EnableBodyCachingEvent(this, routeId));
51+
}
52+
}
53+
4654
@Override
4755
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
4856
this.publisher = publisher;

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactory.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import reactor.retry.Retry;
3636
import reactor.retry.RetryContext;
3737

38-
import org.springframework.cloud.gateway.event.EnableBodyCachingEvent;
3938
import org.springframework.cloud.gateway.filter.GatewayFilter;
4039
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
4140
import org.springframework.cloud.gateway.support.HasRouteId;
@@ -229,10 +228,7 @@ public void reset(ServerWebExchange exchange) {
229228
}
230229

231230
public GatewayFilter apply(String routeId, Repeat<ServerWebExchange> repeat, Retry<ServerWebExchange> retry) {
232-
if (routeId != null && getPublisher() != null) {
233-
// send an event to enable caching
234-
getPublisher().publishEvent(new EnableBodyCachingEvent(this, routeId));
235-
}
231+
enableBodyCaching(routeId);
236232
return (exchange, chain) -> {
237233
trace("Entering retry-filter");
238234

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public List<String> shortcutFieldOrder() {
8989

9090
@Override
9191
public GatewayFilter apply(Config config) {
92+
if (config.getFallbackUri() != null) {
93+
enableBodyCaching(config.getRouteId());
94+
}
9295
ReactiveCircuitBreaker cb = reactiveCircuitBreakerFactory.create(config.getId());
9396
Set<HttpStatus> statuses = config.getStatusCodes()
9497
.stream()

spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.cloud.gateway.test.BaseWebClientTests;
2323
import org.springframework.http.HttpStatus;
24+
import org.springframework.web.reactive.function.BodyInserters;
2425

2526
import static org.assertj.core.api.Assertions.assertThat;
2627
import static org.springframework.http.MediaType.APPLICATION_JSON;
@@ -243,4 +244,11 @@ public void filterStatusCodeResumeWithoutError() {
243244
.valueEquals(ROUTE_ID_HEADER, "circuitbreaker_resume_without_error");
244245
}
245246

247+
@Test
248+
public void filterPostFallback() {
249+
testClient.post().uri("/post").body(BodyInserters.fromValue("hello"))
250+
.header("Host", "www.circuitbreakerfallbackpost.org").exchange().expectStatus()
251+
.isOk().expectBody().json("{\"body\":\"hello\"}");
252+
}
253+
246254
}

spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerTestConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.springframework.http.HttpStatus;
3939
import org.springframework.http.ResponseEntity;
4040
import org.springframework.web.bind.annotation.GetMapping;
41+
import org.springframework.web.bind.annotation.PostMapping;
42+
import org.springframework.web.bind.annotation.RequestBody;
4143
import org.springframework.web.bind.annotation.RequestMapping;
4244
import org.springframework.web.bind.annotation.RequestParam;
4345
import org.springframework.web.bind.annotation.RestController;
@@ -68,6 +70,11 @@ public Map<String, String> fallbackcontroller(@RequestParam("a") String a) {
6870
return Collections.singletonMap("from", "circuitbreakerfallbackcontroller");
6971
}
7072

73+
@PostMapping("/circuitbreakerPostFallbackController")
74+
public Map<String, String> postFallbackController(@RequestBody String body) {
75+
return Collections.singletonMap("body", body);
76+
}
77+
7178
@GetMapping("/circuitbreakerUriFallbackController/**")
7279
public Map<String, String> uriFallbackcontroller(ServerWebExchange exchange, @RequestParam("a") String a) {
7380
return Collections.singletonMap("uri", exchange.getRequest().getURI().toString());

spring-cloud-gateway-server/src/test/resources/application.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ spring:
104104
name: fallbackcmd
105105
fallbackUri: forward:/circuitbreakerFallbackController
106106

107+
# =====================================
108+
- id: circuitbreaker_fallback_test_post
109+
uri: ${test.uri}
110+
predicates:
111+
- Host=**.circuitbreakerfallbackpost.org
112+
filters:
113+
- name: CircuitBreaker
114+
args:
115+
name: fallbackcmd
116+
statusCodes:
117+
- 200
118+
fallbackUri: forward:/circuitbreakerPostFallbackController
119+
107120
# =====================================
108121
- id: circuitbreaker_fallback_test_variables
109122
uri: ${test.uri}

0 commit comments

Comments
 (0)