From 89d4c07e207e9b2caaded0401e78c51593199dfb Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 1 Feb 2017 19:20:26 -0700 Subject: [PATCH] Update to use new response().isCommitted() --- .../cloud/gateway/filter/WriteResponseFilter.java | 7 ------- .../cloud/gateway/filter/route/RedirectToRouteFilter.java | 3 +-- .../cloud/gateway/filter/route/SetStatusRouteFilter.java | 3 +-- .../cloud/gateway/support/ServerWebExchangeUtils.java | 6 ------ 4 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java b/src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java index 39ab79378..4a3686772 100644 --- a/src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java +++ b/src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java @@ -10,7 +10,6 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilterChain; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.RESPONSE_COMMITTED_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.getAttribute; import reactor.core.publisher.Flux; @@ -43,12 +42,6 @@ public class WriteResponseFilter implements GlobalFilter, Ordered { log.trace("WriteResponseFilter start"); ServerHttpResponse response = exchange.getResponse(); - //make other filters aware that the response has been committed - response.beforeCommit(() -> { - exchange.getAttributes().put(RESPONSE_COMMITTED_ATTR, true); - return Mono.empty(); - }); - NettyDataBufferFactory factory = (NettyDataBufferFactory) response.bufferFactory(); //TODO: what if it's not netty diff --git a/src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java b/src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java index 8fd7201d3..1ae6aa973 100644 --- a/src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java +++ b/src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java @@ -9,7 +9,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.server.WebFilter; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.isResponseCommitted; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.parse; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.setResponseStatus; @@ -35,7 +34,7 @@ public class RedirectToRouteFilter implements RouteFilter { return (exchange, chain) -> chain.filter(exchange).then(() -> { - if (!isResponseCommitted(exchange)) { + if (!exchange.getResponse().isCommitted()) { setResponseStatus(exchange, httpStatus); final ServerHttpResponse response = exchange.getResponse(); diff --git a/src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java b/src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java index ba8bee7d6..39e914ce2 100644 --- a/src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java +++ b/src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java @@ -4,7 +4,6 @@ import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; import org.springframework.http.HttpStatus; import org.springframework.web.server.WebFilter; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.isResponseCommitted; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.setResponseStatus; import reactor.core.publisher.Mono; @@ -31,7 +30,7 @@ public class SetStatusRouteFilter implements RouteFilter { // option 2 (runs in reverse filter order) return chain.filter(exchange).then(() -> { // check not really needed, since it is guarded in setStatusCode, but it's a good example - if (!isResponseCommitted(exchange)) { + if (!exchange.getResponse().isCommitted()) { setResponseStatus(exchange, httpStatus); } return Mono.empty(); diff --git a/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java b/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java index fc862e370..5b7db2c53 100644 --- a/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java +++ b/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java @@ -15,7 +15,6 @@ public class ServerWebExchangeUtils { public static final String GATEWAY_ROUTE_ATTR = "gatewayRoute"; public static final String GATEWAY_REQUEST_URL_ATTR = "gatewayRequestUrl"; public static final String GATEWAY_HANDLER_MAPPER_ATTR = "gatewayHandlerMapper"; - public static final String RESPONSE_COMMITTED_ATTR = "responseCommitted"; public static T getAttribute(ServerWebExchange exchange, String attributeName, Class type) { if (exchange.getAttributes().containsKey(attributeName)) { @@ -28,11 +27,6 @@ public class ServerWebExchangeUtils { return null; } - public static boolean isResponseCommitted(ServerWebExchange exchange) { - Boolean responseCommitted = getAttribute(exchange, RESPONSE_COMMITTED_ATTR, Boolean.class); - return responseCommitted != null && responseCommitted; - } - public static boolean setResponseStatus(ServerWebExchange exchange, HttpStatus httpStatus) { boolean response = exchange.getResponse().setStatusCode(httpStatus); if (!response && logger.isWarnEnabled()) {