mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
!1373 getClientIP 优先获取传入的请求头信息
Merge pull request !1373 from handy/handy
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -391,7 +391,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
public String getClientIP(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);
|
||||
|
Reference in New Issue
Block a user