@ -1,11 +1,11 @@
@@ -1,11 +1,11 @@
package org.springframework.cloud.gateway.filter.route ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogFactory ;
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 ;
@ -13,21 +13,10 @@ import reactor.core.publisher.Mono;
@@ -13,21 +13,10 @@ import reactor.core.publisher.Mono;
* @author Spencer Gibb
* /
public class SetStatusRouteFilter implements RouteFilter {
protected final Log logger = LogFactory . getLog ( getClass ( ) ) ;
@Override
public WebFilter apply ( String statusString , String [ ] args ) {
HttpStatus httpStatus ;
try {
int status = Integer . parseInt ( statusString ) ;
httpStatus = HttpStatus . valueOf ( status ) ;
} catch ( NumberFormatException e ) {
// try the enum string
httpStatus = HttpStatus . valueOf ( statusString . toUpperCase ( ) ) ;
}
final HttpStatus finalStatus = httpStatus ;
final HttpStatus httpStatus = ServerWebExchangeUtils . parse ( statusString ) ;
//TODO: caching can happen here
return ( exchange , chain ) - > {
@ -43,10 +32,7 @@ public class SetStatusRouteFilter implements RouteFilter {
@@ -43,10 +32,7 @@ public class SetStatusRouteFilter implements RouteFilter {
return chain . filter ( exchange ) . then ( ( ) - > {
// check not really needed, since it is guarded in setStatusCode, but it's a good example
if ( ! isResponseCommitted ( exchange ) ) {
boolean response = exchange . getResponse ( ) . setStatusCode ( finalStatus ) ;
if ( ! response & & logger . isWarnEnabled ( ) ) {
logger . warn ( "Unable to set status code to " + finalStatus + ". Response already committed." ) ;
}
setResponseStatus ( exchange , httpStatus ) ;
}
return Mono . empty ( ) ;
} ) ;