mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
getClientIP优先获取传入的请求头信息(pr#1373@Gitee)
This commit is contained in:
@@ -235,7 +235,7 @@ public class SunServerRequest extends SunServerExchangeBase implements ServerReq
|
|||||||
public String getClientIP(final String... otherHeaderNames) {
|
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"};
|
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)) {
|
if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
|
||||||
headers = ArrayUtil.addAll(headers, otherHeaderNames);
|
headers = ArrayUtil.addAll(otherHeaderNames, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getClientIPByHeader(headers);
|
return getClientIPByHeader(headers);
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class ServletUtil {
|
|||||||
public static String getClientIP(final HttpServletRequest request, final String... otherHeaderNames) {
|
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"};
|
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)) {
|
if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
|
||||||
headers = ArrayUtil.addAll(headers, otherHeaderNames);
|
headers = ArrayUtil.addAll(otherHeaderNames, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getClientIPByHeader(request, headers);
|
return getClientIPByHeader(request, headers);
|
||||||
|
|||||||
Reference in New Issue
Block a user