|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.inspect.gateway.filter; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
@ -26,19 +27,26 @@ public class RequestParamGlobalFilter implements GlobalFilter, Ordered { |
|
|
|
private Logger logger = LoggerFactory.getLogger(RequestParamGlobalFilter.class); |
|
|
|
private static final List<HttpMessageReader<?>> messageReaders = HandlerStrategies.withDefaults().messageReaders(); |
|
|
|
|
|
|
|
private static final List<String> PATH_WHITE_LIST = Arrays.asList( |
|
|
|
"/patrol/task/add", |
|
|
|
"/example/path2" |
|
|
|
); |
|
|
|
|
|
|
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { |
|
|
|
ServerHttpRequest request = exchange.getRequest(); |
|
|
|
HttpHeaders headers = request.getHeaders(); |
|
|
|
MediaType contentType = headers.getContentType(); |
|
|
|
long contentLength = headers.getContentLength(); |
|
|
|
final String uriPath = request.getURI().getPath(); |
|
|
|
return contentLength <= 0L |
|
|
|
final String path = request.getURI().getPath(); |
|
|
|
boolean bWhite = isWhiteListed(path); |
|
|
|
if (contentLength <= 0L |
|
|
|
|| !MediaType.APPLICATION_JSON.equals(contentType) && !MediaType.APPLICATION_JSON_UTF8.equals(contentType) |
|
|
|
|| uriPath.contains("/task/add") |
|
|
|
|| uriPath.contains("/task/save") |
|
|
|
? |
|
|
|
chain.filter(exchange) : |
|
|
|
this.readBody(exchange, chain); |
|
|
|
|| bWhite) { |
|
|
|
logger.info("RequestParamGlobalFilter body transfer omitting, path: {}, bWhite: {}", path, bWhite); |
|
|
|
return chain.filter(exchange); |
|
|
|
} |
|
|
|
|
|
|
|
return readBody(exchange, chain); |
|
|
|
} |
|
|
|
|
|
|
|
private Mono<Void> readBody(ServerWebExchange exchange, GatewayFilterChain chain) { |
|
|
|
@ -65,4 +73,8 @@ public class RequestParamGlobalFilter implements GlobalFilter, Ordered { |
|
|
|
public int getOrder() { |
|
|
|
return Integer.MIN_VALUE; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isWhiteListed(String path) { |
|
|
|
return PATH_WHITE_LIST.stream().anyMatch(path::startsWith); |
|
|
|
} |
|
|
|
} |