mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for getRemoteAddress.
This commit is contained in:
@@ -262,7 +262,6 @@ public class WebSessionStat {
|
||||
}
|
||||
|
||||
if (remoteAddresses.length() > 256) {
|
||||
LOG.error("session ip change too many");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,19 +23,54 @@ public class DruidWebUtils {
|
||||
|
||||
public static String getRemoteAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip != null && !isValidAddress(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
if (ip != null && !isValidAddress(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
if (ip != null && !isValidAddress(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
if (ip != null && !isValidAddress(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
private static boolean isValidAddress(String ip) {
|
||||
if (ip == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ip.length(); ++i) {
|
||||
char ch = ip.charAt(i);
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
} else if (ch >= 'A' && ch <= 'F') {
|
||||
} else if (ch >= 'a' && ch <= 'f') {
|
||||
} else if (ch == '.' || ch == ':') {
|
||||
//
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String getContextPath_2_5(ServletContext context) {
|
||||
String contextPath = context.getContextPath();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user