Kaynağa Gözat

网关更新

李学强 5 ay önce
ebeveyn
işleme
9f6089fb0d

+ 10 - 0
lhb-gateway/src/main/java/com/kxs/gateway/api/filter/RequestDecoderFilter.java

@@ -23,8 +23,10 @@ import org.springframework.http.MediaType;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
 import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.util.AntPathMatcher;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
+import org.springframework.util.PathMatcher;
 import org.springframework.web.reactive.function.server.HandlerStrategies;
 import org.springframework.web.reactive.function.server.ServerRequest;
 import org.springframework.web.server.ServerWebExchange;
@@ -66,6 +68,9 @@ public class RequestDecoderFilter extends AbstractGatewayFilterFactory<Object> {
 
     private static final List<String> FILE_TYPES = List.of("multipart/form-data");
 
+
+    private final PathMatcher pathMatcher = new AntPathMatcher();
+
     @Override
     public GatewayFilter apply(Object config) {
         return (exchange, chain) -> {
@@ -79,6 +84,11 @@ public class RequestDecoderFilter extends AbstractGatewayFilterFactory<Object> {
             if (!filterUrl.isEmpty() && filterUrl.contains(path)) {
                 return chain.filter(exchange);
             }
+            boolean match = filterUrl.stream().anyMatch(url -> pathMatcher.match(url, path));
+            if (match) {
+                return chain.filter(exchange);
+            }
+
             if (contentType != null && FILE_TYPES.stream().anyMatch(contentType.toString()::startsWith)) {
                 // 这是一个文件请求
                 return chain.filter(exchange);