getClientIP优先获取传入的请求头信息(pr#1373@Gitee)

This commit is contained in:
Looly
2025-08-11 11:19:36 +08:00
parent cc0b4b10c7
commit f20536ea12
2 changed files with 2 additions and 2 deletions

View File

@@ -235,7 +235,7 @@ public class SunServerRequest extends SunServerExchangeBase implements ServerReq
public String getClientIP(final String... otherHeaderNames) {
String[] headers = {"X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"};
if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
headers = ArrayUtil.addAll(headers, otherHeaderNames);
headers = ArrayUtil.addAll(otherHeaderNames, headers);
}
return getClientIPByHeader(headers);

View File

@@ -211,7 +211,7 @@ public class ServletUtil {
public static String getClientIP(final HttpServletRequest request, final String... otherHeaderNames) {
String[] headers = {"X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"};
if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
headers = ArrayUtil.addAll(headers, otherHeaderNames);
headers = ArrayUtil.addAll(otherHeaderNames, headers);
}
return getClientIPByHeader(request, headers);