Browse Source

Filtering the status codes just once

pull/1836/head
Ryan Baxter 4 years ago
parent
commit
ef32cb7e9b
  1. 9
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactory.java

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

@ -87,17 +87,16 @@ public abstract class SpringCloudCircuitBreakerFilterFactory extends @@ -87,17 +87,16 @@ public abstract class SpringCloudCircuitBreakerFilterFactory extends
@Override
public GatewayFilter apply(Config config) {
ReactiveCircuitBreaker cb = reactiveCircuitBreakerFactory.create(config.getId());
Set<HttpStatus> statuses = config.getStatusCodes().stream()
.map(HttpStatusHolder::parse)
.filter(statusHolder -> statusHolder.getHttpStatus() != null)
.map(HttpStatusHolder::getHttpStatus).collect(Collectors.toSet());
return new GatewayFilter() {
@Override
public Mono<Void> filter(ServerWebExchange exchange,
GatewayFilterChain chain) {
return cb.run(chain.filter(exchange).doOnSuccess(v -> {
Set<HttpStatus> statuses = config.getStatusCodes().stream()
.map(HttpStatusHolder::parse)
.filter(statusHolder -> statusHolder.getHttpStatus() != null)
.map(HttpStatusHolder::getHttpStatus)
.collect(Collectors.toSet());
if (statuses.contains(exchange.getResponse().getStatusCode())) {
HttpStatus status = exchange.getResponse().getStatusCode();
exchange.getResponse().setStatusCode(null);

Loading…
Cancel
Save