算法模块删除不必要的代码,有备份,如果存疑就联系我
This commit is contained in:
@@ -4,6 +4,9 @@ import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -80,7 +83,23 @@ public class IpUtils {
|
||||
ipAddress = ipAddress.substring(0, index);
|
||||
}
|
||||
}
|
||||
return ipAddress;
|
||||
|
||||
String clientIp = request.getHeaders().getFirst("X-Forwarded-For");
|
||||
if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getHeaders().getFirst("X-Real-IP");
|
||||
if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getRemoteAddress().getAddress().getHostAddress();
|
||||
}
|
||||
} else {
|
||||
// X-Forwarded-For 头可能包含多个 IP,取第一个
|
||||
int index = clientIp.indexOf(',');
|
||||
if (index > 0) {
|
||||
clientIp = clientIp.substring(0, index).trim();
|
||||
}
|
||||
}
|
||||
System.out.println("new------:"+clientIp);
|
||||
// System.out.println("old------:"+ipAddress);
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user