!1373 getClientIP 优先获取传入的请求头信息

Merge pull request !1373 from handy/handy
This commit is contained in:
Looly
2025-08-11 03:15:49 +00:00
committed by Gitee
3 changed files with 3 additions and 3 deletions

View File

@@ -215,7 +215,7 @@ public class JakartaServletUtil {
public static String getClientIP(HttpServletRequest request, 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);

View File

@@ -215,7 +215,7 @@ public class ServletUtil {
public static String getClientIP(HttpServletRequest request, 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);