Browse Source

Update to use new response().isCommitted()

pull/41/head
Spencer Gibb 8 years ago
parent
commit
89d4c07e20
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 7
      src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java
  2. 3
      src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java
  3. 3
      src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java
  4. 6
      src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java

7
src/main/java/org/springframework/cloud/gateway/filter/WriteResponseFilter.java

@ -10,7 +10,6 @@ import org.springframework.web.server.ServerWebExchange; @@ -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 { @@ -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

3
src/main/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilter.java

@ -9,7 +9,6 @@ import org.springframework.http.HttpStatus; @@ -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 { @@ -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();

3
src/main/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilter.java

@ -4,7 +4,6 @@ import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; @@ -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 { @@ -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();

6
src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java

@ -15,7 +15,6 @@ public class ServerWebExchangeUtils { @@ -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> T getAttribute(ServerWebExchange exchange, String attributeName, Class<T> type) {
if (exchange.getAttributes().containsKey(attributeName)) {
@ -28,11 +27,6 @@ public class ServerWebExchangeUtils { @@ -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()) {

Loading…
Cancel
Save