From a43e324ef10aa6e5bc4ab5ec2a62b593cfee974e Mon Sep 17 00:00:00 2001 From: AlexBob <5199840@qq.com> Date: Tue, 4 Jun 2024 10:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB):=20=E4=BD=BF=E7=94=A8`List`=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2`StringUtils`=E7=AE=80=E5=8C=96IP=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/platform/boot/commons/utils/ContextUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/boot/platform/src/main/java/com/platform/boot/commons/utils/ContextUtils.java b/boot/platform/src/main/java/com/platform/boot/commons/utils/ContextUtils.java index 5f2f1950..66d31a13 100644 --- a/boot/platform/src/main/java/com/platform/boot/commons/utils/ContextUtils.java +++ b/boot/platform/src/main/java/com/platform/boot/commons/utils/ContextUtils.java @@ -15,13 +15,13 @@ import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import java.util.List; import java.util.Objects; /** @@ -68,10 +68,9 @@ public static byte[] objectToBytes(Object object) { public static String getClientIpAddress(ServerHttpRequest httpRequest) { HttpHeaders headers = httpRequest.getHeaders(); for (String header : IP_HEADER_CANDIDATES) { - String ipList = headers.getFirst(header); - if (ipList != null && !ipList.isEmpty() && !"unknown".equalsIgnoreCase(ipList)) { - String[] ipArray = StringUtils.commaDelimitedListToStringArray(ipList); - return ipArray[0]; + List ipList = headers.get(header); + if (ipList != null && !ipList.isEmpty()) { + return ipList.getFirst(); } } return Objects.requireNonNull(httpRequest.getRemoteAddress()).getAddress().getHostAddress();