com.github.houbb.current.user.utils.RequestUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of current-user Show documentation
Show all versions of current-user Show documentation
The current-user tool for java.
package com.github.houbb.current.user.utils;
import com.github.houbb.heaven.annotation.CommonEager;
import com.github.houbb.heaven.util.lang.StringUtil;
import javax.servlet.http.HttpServletRequest;
/**
* 请求参数
* @author binbin.hou
* @since 0.0.12
*/
@CommonEager
public final class RequestUtil {
private RequestUtil(){}
public static String getIp(final HttpServletRequest request) {
// 获取请求IP地址
String ip = request.getHeader("X-Forwarded-For");
if (StringUtil.isEmptyTrim(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtil.isEmptyTrim(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtil.isEmptyTrim(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}