Commit 873c0f41 by 刘鑫

fix: URLEncode 编码后的url参数解析

1 parent fc30f692
......@@ -16,21 +16,12 @@
package com.dituhui.pea.gateway.config;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
......@@ -47,6 +38,13 @@ import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author TrevorLink
......@@ -113,4 +111,9 @@ public class GatewayConfig {
return new CorsWebFilter(source);
}
@Bean
public GlobalRequestUrlDecodeFilter globalRequestUrlDecodeFilter() {
return new GlobalRequestUrlDecodeFilter();
}
}
package com.dituhui.pea.gateway.config;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* URI 参数过滤
*
* @author lsy_xin 2022/3/3 16:29:29
*/
@Slf4j
@AllArgsConstructor
public class GlobalRequestUrlDecodeFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
URI uri = request.getURI();
String path = uri.getPath();
String decodePath = URLDecoder.decode(path, StandardCharsets.UTF_8);
ServerHttpRequest newRequest = exchange.getRequest().mutate().path(decodePath).build();
return chain.filter(exchange.mutate().request(newRequest).build());
}
@Override
public int getOrder() {
return Integer.MIN_VALUE + 1;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!