fix(通用模块):登录手机号获取异常逻辑优化,无效http请求异常处理
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.central.gateway.filter;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 不合法请求过滤器
|
||||
*
|
||||
* @author lsl
|
||||
* @date 2025/03/11
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class RequestFilter implements GlobalFilter {
|
||||
|
||||
private boolean isValidMethod(String method) {
|
||||
// 简单的方法名验证,只允许常见的 HTTP 方法
|
||||
return method.matches("^(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE)$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest httpRequest = exchange.getRequest();
|
||||
String method = httpRequest.getMethod().toString();
|
||||
if (isValidMethod(method)) {
|
||||
return chain.filter(exchange);
|
||||
} else {
|
||||
return exchange.getResponse().setComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user